2014年03月30日 14:32:00

Shell for quick start with CodeIgniter in koding

作者: 
本文展示如何使用Shell快速创建CI App,实现共用核心框架,无限拷贝生成新App。(其实就是想学习Shell,顺便弄了这玩意儿~)

创建应用文件:createCIApp.sh

#!/bin/bash

#@author Zjmainstay
#@website http://zjmainstay.cn
#@copyright GPL
# @version 1.0
# @year 2014

#Get file path
FILE_PATH=$0
FILE_PATH_BAK="$FILE_PATH.bak"
FILE_PATH_INSTALLED="$FILE_PATH.installed"

pwd
FILE_DIR=`dirname $0`
FILE_NAME=${FILE_PATH##*/}

#App name
read -p "Please input your app name: " app

if [ -z $app ]
then
	echo "Please input your app name."
	exit
fi

function getpasswordsum() {
	local password=$1
	#Save password in tmp file
	local PASSWORD_FILE="/tmp/passwd"
	echo $password > $PASSWORD_FILE

	#md5sum password file
	local md5sumfile=`md5sum $PASSWORD_FILE`

	#remove it
	rm $PASSWORD_FILE

	#get md5sum part
	passwordsum=${md5sumfile%% *}

	echo $passwordsum
}

#install password
INSTALL_PASSWORD="install_password"

#realpassword set before for match
realpasswordsum="$INSTALL_PASSWORD"

if [ $realpasswordsum == $INSTALL_PASSWORD ]
then
	read -p "Please set your install password: " initpassword
	read -p "Please confirm your install password: " confirmpassword
	if [ $initpassword != $confirmpassword ]
	then
		echo "Password is not match."
		exit
	else	
		#install password
		initpasswordsum=`getpasswordsum $initpassword`
		CMD_REPLACE_PASSWORD="cat $FILE_NAME | sed 's/realpasswordsum=\"\$INSTALL_PASSWORD\"/realpasswordsum=\"$initpasswordsum\"/g' > $FILE_PATH_INSTALLED"
		echo $CMD_REPLACE_PASSWORD | sh
	fi
else 
	# Password check
	read -p "Please input your password: " password
	if [ -z $password ]
	then
		echo "Please input your password."
		exit
	else
		inputpasswordsum=`getpasswordsum $password`
		if [ "$inputpasswordsum" != "$realpasswordsum" ]
		then
			echo "Password Error."
			exit
		fi
	fi
fi

#######=============================

#path
HOME_PATH=~
FRAMEWORK_PATH="$HOME_PATH/Framework"
CI_FRAMEWORK_PATH="$FRAMEWORK_PATH/CodeIgniter"
WEB_PATH="$HOME_PATH/Web"
APP_PATH="$HOME_PATH/Applications/$app"
APP_PUBLIC_PATH="$APP_PATH/www"

#create framework dir
if [ ! -d $FRAMEWORK_PATH ]
then
	mkdir $FRAMEWORK_PATH
fi

#download CodeIgniter Framework
if [ ! -d $CI_FRAMEWORK_PATH ]
then
	cd $FRAMEWORK_PATH
	git clone https://github.com/EllisLab/CodeIgniter
fi

#check if app exists
if [ -d $APP_PATH ]
then
	echo "App is exists, Please change your app name"
	exit
fi

#do create app

#create app dir
mkdir $APP_PATH

#copy CodeIgniter framework to app dir
cp -R $CI_FRAMEWORK_PATH/* $APP_PATH

#delete system dir, use symbol link instead 
rm -rf $APP_PATH/system
ln -s $CI_FRAMEWORK_PATH/system $APP_PATH/system

#rm user guide src dir
rm -rf $APP_PATH/user_guide_src

#create web visit dir, use symbol link from application path
mkdir $APP_PUBLIC_PATH

#replace app visit file to relative path
CMD_REPLACE="cat $APP_PATH/index.php | sed \"s/'system'/'..\/system'/g\" | sed \"s/'application'/'..\/application'/g\" > $APP_PUBLIC_PATH/index.php"
echo $CMD_REPLACE | sh

#link app public dir to web
ln -s $APP_PUBLIC_PATH $WEB_PATH/$app

#if first install
if [ -f $FILE_PATH_INSTALLED ]
then
	#bak install sh, and replace into installed
	mv $FILE_PATH $FILE_PATH_BAK
	mv $FILE_PATH_INSTALLED $FILE_PATH
	chmod 744 $FILE_PATH
fi

echo "App $app created."

删除应用文件:deleteCIApp.sh

#!/bin/bash

#@author Zjmainstay
#@website http://zjmainstay.cn
#@copyright GPL
# @version 1.0
# @year 2014

#Get file path
FILE_PATH=$0
FILE_PATH_BAK="$FILE_PATH.bak"
FILE_PATH_INSTALLED="$FILE_PATH.installed"

pwd
FILE_DIR=`dirname $0`
FILE_NAME=${FILE_PATH##*/}

#App name
read -p "Please input your app name: " app

if [ -z $app ]
then
        echo "Please input your app name."
        exit
fi

function getpasswordsum() {
	local password=$1
	#Save password in tmp file
	local PASSWORD_FILE="/tmp/passwd"
	echo $password > $PASSWORD_FILE

	#md5sum password file
	local md5sumfile=`md5sum $PASSWORD_FILE`

	#remove it
	rm $PASSWORD_FILE

	#get md5sum part
	passwordsum=${md5sumfile%% *}

	echo $passwordsum
}

#install password
INSTALL_PASSWORD="install_password"

#realpassword set before for match
realpasswordsum="$INSTALL_PASSWORD"

if [ $realpasswordsum == $INSTALL_PASSWORD ]
then
	read -p "Please set your install password: " initpassword
	read -p "Please confirm your install password: " confirmpassword
	if [ $initpassword != $confirmpassword ]
	then
		echo "Password is not match."
		exit
	else
		#install password
		initpasswordsum=`getpasswordsum $initpassword`
		CMD_REPLACE_PASSWORD="cat $FILE_NAME | sed 's/realpasswordsum=\"\$INSTALL_PASSWORD\"/realpasswordsum=\"$initpasswordsum\"/g' > $FILE_PATH_INSTALLED"
		echo $CMD_REPLACE_PASSWORD | sh
	fi
else
	# Password check
	read -p "Please input your password: " password
	if [ -z $password ]
	then
		echo "Please input your password."
		exit
	else
		inputpasswordsum=`getpasswordsum $password`
		if [ "$inputpasswordsum" != "$realpasswordsum" ]
		then
			echo "Password Error."
			exit
		fi
	fi
fi

#######=============================

#Do remove app
HOME_PATH=~
APP_PATH="$HOME_PATH/Applications/$app"
WEB_PATH="$HOME_PATH/Web"

#check app exists
if [ ! -d $APP_PATH ]
then
	echo "App $app is not exists, please check it."
	if [ -f $FILE_PATH_INSTALLED ]
	then
		rm $FILE_PATH_INSTALLED
	fi
	exit
fi


#remove app dir
rm -rf $APP_PATH

#remove web symbol link
rm $WEB_PATH/$app

#if first install
if [ -f $FILE_PATH_INSTALLED ]
then
	#bak install sh, and replace into installed
	mv $FILE_PATH $FILE_PATH_BAK
	mv $FILE_PATH_INSTALLED $FILE_PATH
	chmod 744 $FILE_PATH
fi

echo "App $app removed."

Friendly Link: Koding.com - 免费Linux开发平台

未经同意禁止转载!
转载请附带本文原文地址:Shell for quick start with CodeIgniter in koding,首发自 Zjmainstay学习笔记
阅读( 2717 )
看完顺手点个赞呗:
(6 votes)

1.PHP cURL群:PHP cURL高级技术
2.正则表达式群:专精正则表达式
3. QQ联系(加请说明):QQ联系博主(951086941)
4. 邮箱:zjmainstay@163.com
5. 打赏博主:

  1. 模拟登录后数据采集
  2. 网页内容数据采集
  3. 采集内容正则解析
  4. 数据采集难题咨询

阿里云幸运券分享
网站总访问量: