网站发布SHELL自动化

#!/bin/sh
# 操作站点文件:移动E盘phpweb目录下的网站和相关Mysql数据到Linux下
# 注意变量=两边不能有空格,正确格式:a="1", 错误格式:a = "1"
# 注意判断空格,正确格式:[ "$1"  =  "--del" ],错误格式:[ "$1" = "--del" ]
helpfun(){
	echo "
descript:
 1)--add 操作:移动 /media/e/phpweb/ 目录下的网站到  /opt/lampp/htdocs/,并且把对应数据库 /media/f/NPMserv/MySQL5.1/data/ 移动到 /opt/lampp/var/mysql/
 2)--del 操作:移除 /opt/lampp/htdocs/ 下的站点和对应数据库
 
usage: website option arg [arg1]

options:
 --add 移动站点
 --del 删除站点
 --help show the help
 
例子:
 website --add ecshop
 website --add ecshop wordpress ...
"
	exit;
}

# cmd 命令操作方式
case "$1" in
--add)
	sourcePath="/media/e/phpweb/"
	sourceDataPath="/media/f/NPMserv/MySQL5.1/data/"
	targetPath="/opt/lampp/htdocs/"
	targetDataPath="/opt/lampp/var/mysql/";;
--del)
	targetPath="/opt/lampp/htdocs/"
	targetDataPath="/opt/lampp/var/mysql/";;
--help)
	helpfun;;
esac

# loop 处理
for thedir in $*
do
	if [ "$thedir" != "$1" ]; then
		if [ "$1" = "--add" ]; then
			echo "正在复制站点到 ${targetPath}${thedir}"
			# 复制站点文件
			sudo cp -R ${sourcePath}${thedir} ${targetPath}${thedir}
			sudo chown -R nobody:hanson ${targetPath}${thedir}
			sudo chmod -R g+rw ${targetPath}${thedir}
			# 复制站点数据库
			sudo cp -R ${sourceDataPath}${thedir} ${targetDataPath}${thedir}
			sudo chown -R nobody ${targetDataPath}${thedir}
		elif [ "$1" = "--del" ]; then
			echo "正在删除站点 ${targetPath}${thedir}"
			# 删除站点文件
			sudo rm -R ${targetPath}${thedir}
			# 删除数据库
			sudo rm -R ${targetDataPath}${thedir}
		else
			#donothing
			helpfun
		fi
	fi
done
echo "操作成功!"


你可能感兴趣的:(网站发布SHELL自动化)