<NME> deploy.sh
<BEF> #!/bin/bash
cur_dir=`old=\`pwd\`; cd \`dirname $0\`; echo \`pwd\`; cd $old;`
prj=`basename $cur_dir`
env=$1
iphp_dir=/data/lib/iphp
if [ -z "$env" ]; then
	echo "Usage: $0 ENV"
	echo "    ENV: dev, online"
	exit
fi

echo ""
echo "#######################################"
echo "Project: $prj"
echo ""
echo "deploy $env."

ln -sf $cur_dir/app/config/config_${env}.php $cur_dir/app/config/config.php
ln -sf $cur_dir/app/config/nginx_${env}.conf /etc/nginx/conf.d/$prj.conf

mkdir -p /data/applogs/$prj
chmod ugo+rwx /data/applogs /data/applogs/$prj

echo "#######################################"
echo ""
echo ""

if [ "$env" = "online" ]; then
	deploy_online
else
	deploy_dev
fi


# update assets.json
if [ "$env" = "online" ]; then
	cd $dep_dir
fi
php $iphp_dir/tools/assets_md5.php js css imgs static
if [ $? -eq 0 ]; then
	echo "update assets.json done."
else
	echo "update assets.json fail! please resolve it!"
fi
cd $cur_dir
# end update assets.json


sh $prj_dir/server.sh restart


echo ""
echo "done."
echo "#######################################"
echo ""

<MSG> udpate deploy.sh

<DFF> @@ -6,20 +6,70 @@ env=$1
 if [ -z "$env" ]; then
 	echo "Usage: $0 ENV"
 	echo "    ENV: dev, online"
-	exit
+	exit 1
 fi
 
+
+prj_dir=/data/www/$prj
+dep_dir=/data/deploy_www/$prj.dep.`date +%Y%m%d_%H%M%S`
+
+function deploy_dev()
+{
+	rm -f $prj_dir
+	ln -sf $cur_dir $prj_dir
+	ln -sf $cur_dir/app/config/config_${env}.php $cur_dir/app/config/config.php
+	ln -sf $cur_dir/app/config/nginx_${env}.conf /etc/nginx/conf.d/$prj.conf
+}
+
+function deploy_online()
+{
+	mkdir -p /data/applogs/$prj
+	chmod ugo+rwx /data/applogs /data/applogs/$prj
+
+	mkdir -p /data/deploy_www
+	chmod ugo+rx /data/deploy_www
+	
+	old_deploys=`ls /data/deploy_www/ | grep "^$prj\.dep\."`
+
+	echo "copy files..."
+	rsync -a --exclude '.*' $cur_dir/ $dep_dir/
+	if [ $? -ne "0" ]; then
+		echo "Failed to deploy project!"
+		exit 1
+	fi
+	chmod ugo+rx $dep_dir
+
+	echo "create links..."
+	# 将项目软链到当前版本
+	rm -f $prj_dir
+	ln -sf $dep_dir $prj_dir
+
+	ln -sf $prj_dir/app/config/config_${env}.php $prj_dir/app/config/config.php
+	ln -sf $prj_dir/app/config/nginx_${env}.conf /etc/nginx/conf.d/$prj.conf
+
+	# 备份旧的版本
+	mkdir -p /data/deploy_www/backup
+	for i in $old_deploys; do
+		echo "backup old deploy: $i"
+		mv /data/deploy_www/$i /data/deploy_www/backup
+	done
+}
+
+
 echo ""
 echo "#######################################"
 echo "Project: $prj"
+echo "Env    : $env"
 echo ""
-echo "deploy $env."
 
-ln -sf $cur_dir/app/config/config_${env}.php $cur_dir/app/config/config.php
-ln -sf $cur_dir/app/config/nginx_${env}.conf /etc/nginx/conf.d/$prj.conf
+if [ "$env" = "online" ]; then
+	deploy_online
+else
+	deploy_dev
+fi
 
-mkdir -p /data/applogs/$prj
-chmod ugo+rwx /data/applogs /data/applogs/$prj
 
+echo ""
+echo "done."
 echo "#######################################"
 echo ""

udpate deploy.sh