svn 發布腳本整合
linux多實例apache+svn部署
1.首先創建多實例目錄
svnadmin create /svn/psm/
svnadmin create /svn/sh/
2.賦予權限:
chmod -R 777 /svn/psm /svn/sh
chown -R apache.apache /svn/psm /svn/sh
3.修改用戶權限:
vim /svn/psm/conf/svnserve.conf
anon-access = none
auth-access = write
4.整合Apache
vi /etc/httpd/conf.d/subversion.conf 加入以下:
多少個實例就添加幾個location
<Location /psm>
DAV svn
SVNPath /svn/psm
AuthType Basic
AuthName "svn"
AuthUserFile /var/www/svn/project/conf/passwd
Require valid-user
</Location>
5.啟動svn
svnserver -d --listen-port 3690 -r /svn/sh
svnserver -d --listen-port 3691 -r /svn/psm
6.配置用戶信息
htpasswd -c passwd qinyj
導入項目: svn import /www/download/psm_server -m "psm_server" file:///svn/psm/ --force-log
svn import /www/downloadsh -m "sh" file:///svn/psm/ --force-log
svn co http://svn.qinyj.top/sh psm #checkout代碼。
svn up svn目錄 --username aaa svn代碼目錄。 #更新代碼庫。會根據隱藏文件.svn 與服務器更新代碼,如果本地工作目錄沒有會Add。
svn ci -m "備註信息" --username aaa svn代碼目錄。#提交到代碼庫。或者到svn目錄裏面svn ci -m "備註" --username aaa
7.更新提交腳本
[ ! -d /code/wordpress ] && mkdir -p /code/wordpress && svn co http://svn.${svn_name}.top/sh/wordpress/ /code/wordpress && exit 1 || cd /code/wordpress #檢查有沒有創建工作目錄
cd /code/wordpress #進入到工作目錄
update_svn()
{
svn update --username ${svn_name}
if [ $? -ne 0 ];then
echo "svn update failed"
exit 1
fi
VERSION=`svn info |awk -F"[ ]+" ‘/Revision/{print $2}‘`
TEMP="`date +%Y%m%d`${VERSION}"
NUM=`echo ${TEMP}+1|bc`
echo -e "####################\nsvn update complete"
}
svn_commit ()
{
VERSION=`svn info |awk -F"[ ]+" ‘/Revision/{print $2}‘`
echo "cd /code/wordpress"
cd /code/wordpress
[ ! -d /root/shell_log ] && mkdir -p /root/shell_log
mkdir -p /root/shell_log/${VERSION}
svn status |awk ‘{if($1=="!") print $0}‘ |cut -b 9- >/root/shell_log/${VERSION}/svn_del.log
svn status |awk ‘{if($1=="?") print $0}‘ |cut -b 9- >/root/shell_log/${VERSION}/svn_add.log
svn status |awk ‘{if($1=="M") print $0}‘ |cut -b 9- >/root/shell_log/${VERSION}/svn_change.log
while read line ;do svn delete "$line" ;done </root/shell_log/${VERSION}/svn_del.log && echo "svn delete complete"
while read line ;do svn add "$line" ;done </root/shell_log/${VERSION}/svn_add.log && echo "svn add complete"
svn commit -m "`date +%Y%m%d%H%M%S`" --username ${svn_name} && echo "svn commit complete"
#刪除認證文件
rm -f /root/.subversion/auth/svn.simple/*
}
svn 發布腳本整合