======================= 开发机
#!/bin/sh
#SVN路径 主干
#svn_path_1="http://192.168.1.201:8080/svn/TEST/trunk/06-%E7%A8%8B%E5%BA%8F%E6%BA%90%E7%A0%81/01-%E6%BA%90%E7%A0%81/test"
#SVN路径 分支
svn_path_1="http://192.168.1.201:8080/svn/TEST/branches/1.1.4.3648sp1/test"
#SVN用户名/密码
svn_user="svncheck"
svn_passwd="svncheck"
#工作目录
cur_path="/usr/local/shell/svn"
#临时目录
tmp_path_1="$cur_path/tmp/test"
#tmp_path_2="$cur_path/tmp/lib"
#配置文件备份目录
bak_path="$cur_path/bakdir_test"
#上次取下的版本
rev_file="$cur_path/rev_file_test"
#svn记录
svn_log="$cur_path/svn_test.log"
#SVN备注记录
svn_msg_log="$cur_path/svn_msg.log"
#简洁日志文件
file="$cur_path/tmp/test_log"
#检查版本号
test -f "$rev_file" && latest_rev =`cat $rev_file`
if [ "$?" != 0 ];then
latest_rev=1
fi
#开始执行时间
echo `date +%F......%T` >>$svn_log
#取SVN上最新版本号
head_rev=`svn info --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive --xml $svn_path_1 | grep "revision" | head -1 |cut -d '"' -f2`
if [ "$head_rev" -gt "$latest_rev"
];then
svn export -r$head_rev
--force --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive $svn_path_1 $tmp_path_1 >/dev/null 2>&1
# svn export --force --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive $svn_path_1 $tmp_path_1 >>$svn_log
# svn export --force --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive $svn_path_2 $tmp_path_2 >>$svn_log
if [ "$?" == 0 ];then
echo "$head_rev" > $rev_file
fi
#取svn上备注
svn log $svn_path_1 -r $latest_rev:$head_rev --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive > $svn_msg_log
#简洁备注
echo "TEST.DEV开发环境代码已更新。SVN版本号为:$head_rev。主要做了以下修改:" > $file
awk -v RS='------------------------------------------------------------------------' -v OFS='|' '$1=$1' $svn_msg_log | awk -F'|' '{j="";for(i=16;i<=NF;i++){j=j" "$i};print $4,j}' | sort -k1,2|uniq >> $file
#最终不变的配置文件
# rm -fr $tmp_path_1/static/domain.inc
#剔除不发布的目录和文件
rm -rf $tmp_path_1/protected/runtime/
rm -rf $tmp_path_1/protected/config/extends/
rm -rf $tmp_path_1/protected/data/vcode/
rm -f $tmp_path_1/www/index.php
rm -rf $tmp_path_1/www/assets/
# chmod -R 777 $tmp_path_1/theme/logo
# chmod -R 777 $tmp_path_1/static
#发布到本机最终目录
cp -fr $tmp_path_1/* /var/www/WWW_SSC_DEV/
#发布到本机最终目录
# if [ `ls -al $tmp_path_2|wc -l` != 3 ];then
# cp -pfr $tmp_path_2/* /var/comm_der/
# cp -pfr $tmp_path_2/* /var/comm_dev/
# cp -pfr $tmp_path_2/* /var/comm_dew/
#发布版本号到192.168.1.76测试环境
scp $rev_file root@192.168.1.76:/usr/local/shell/svn/tmp
#清空临时目录
rm -fr $tmp_path_1/*
#执行其它的脚本
# /var/www/scheme/go
#提示消息
echo "SSC Update Success! Revision:$head_rev"
else
echo "no update! is latest!"
fi
===================== 测试机
#!/bin/sh
#SVN路径 主干
#svn_path_1="http://192.168.1.201:8080/svn/TEST/trunk/06-%E7%A8%8B%E5%BA%8F%E6%BA%90%E7%A0%81/01-%E6%BA%90%E7%A0%81/test"
#SVN路径 分支
svn_path_1="http://192.168.1.201:8080/svn/TEST/branches/1.1.4.3648sp1/test"
#SVN用户名/密码
svn_user="svncheck"
svn_passwd="svncheck"
#工作目录
cur_path="/usr/local/shell/svn"
#临时目录
tmp_path_1="$cur_path/tmp/test"
#tmp_path_2="$cur_path/tmp/lib"
#配置文件备份目录
bak_path="$cur_path/bakdir_test"
#上次取下的版本
rev_file="$cur_path/rev_file_test"
#svn记录
svn_log="$cur_path/svn_test.log"
#SVN备注记录
svn_msg_log="$cur_path/svn_msg.log"
#简洁备注
file="$cur_path/tmp/test_log"
#检查版本号 上次更新的最后版本,作为本次更新的起始版本
test -f "$rev_file" && latest_rev=`cat $rev_file`
if [ "$?" != 0 ];then
latest_rev=1
fi
#echo $latest_rev
#开始执行时间
echo `date +%F......%T` >>$svn_log
#取SVN上最新版本号
#head_rev=`svn info --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive --xml $svn_path_1 | grep "revision" | head -1 |cut -d '"' -f2`
#更新至开发环境传过来的版本号(75):scp过来的截止版本,作为本次更新的终止版本
read head_rev < "$cur_path/tmp/rev_file_test"
if [ "$head_rev" -gt "$latest_rev"
];then
svn export -r$head_rev
--force --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive $svn_path_1 $tmp_path_1 >>$svn_log
# svn export --force --username=$svn_user --password=$svn_passwd --no-auth-cache --non-interactive $svn_path_2 $tmp_path_2 >>$svn_log
if [ "$?" == 0 ];then
echo "$head_rev" > $rev_file
fi
#取svn上备注
echo "TEST.TEST测试环境代码已更新。SVN版本号为:$head_rev。主要做了以下修改:" > $file
svn log $svn_path_1 -r $latest_rev:$head_rev --username=$svn_user --password=$svn_passwd > $svn_msg_log
awk -v RS='------------------------------------------------------------------------' -v OFS='|' '$1=$1' $svn_msg_log | awk -F'|' '{j="";for(i=16;i<=NF;i++){j=j" "$i};print $4,j}' | sort -k1,2|uniq >> $file
#最终不变的配置文件
# rm -fr $tmp_path_1/static/domain.inc
#剔除不发布的目录和文件
rm -rf $tmp_path_1/protected/runtime/
rm -rf $tmp_path_1/protected/config/extends/
rm -rf $tmp_path_1/protected/data/vcode/
rm -f $tmp_path_1/www/index.php
rm -rf $tmp_path_1/www/assets/
# chmod -R 777 $tmp_path_1/theme/logo
# chmod -R 777 $tmp_path_1/static
#发布到本机最终目录
cp -fr $tmp_path_1/* /var/www/WWW_TEST_TEST/
#发布到本机最终目录
# if [ `ls -al $tmp_path_2|wc -l` != 3 ];then
# cp -pfr $tmp_path_2/* /var/comm_der/
# cp -pfr $tmp_path_2/* /var/comm_dev/
# cp -pfr $tmp_path_2/* /var/comm_dew/
# fi
#清空临时目录
rm -fr $tmp_path_1/*
#执行其它的脚本
# /var/www/scheme/go
#提示信息
echo "TEST Update Success! Revision:$head_rev"
sleep 5
else
echo "no update! is latest!"
fi