功能:创建新仓库,修改仓库配置(使用全局配置),配置钩子程序,检索,配置nginx虚拟主机
read -p "仓库名称:" domain
#domain=$1
# SVN仓库路径
svndir=/svn
# SVN配置文件路径
confdir=/svn/conf
# web目录
wwwroot=/data/htdocs
#nginx虚拟主机目录
vhost=/usr/local/nginx/conf/vhost
#创建SVN仓库
if [ -d $svndir/$domain ]
then
echo "仓库已存在"
exit
else
/usr/bin/svnadmin create $svndir/$domain
echo "仓库创建完成"
fi
#拷贝配置文件
/bin/cp $confdir/svnserve.conf $svndir/$domain/conf/svnserve.conf
if [[ $? -eq 0 ]]
then
echo "拷贝配置文件完成"
else
echo "拷贝配置文件失败"
exit
fi
#配置钩子,checkout
if [ -d $wwwroot/$domain ]
then
echo "网站目录已存在,钩子配置停止"
exit
else
/bin/cp $confdir/post-commit $svndir/$domain/hooks
/bin/sed -i "s/domain/$domain/g" $svndir/$domain/hooks/post-commit
/bin/chmod +x /$svndir/$domain/hooks/post-commit
echo "钩子配置完成"
fi
/usr/bin/svn co --username=sync --password sync svn://localhost/$domain $wwwroot/$domain
if [[ $? -eq 0 ]]
then
echo "SVN检索完成"
else
echo "SVN检索失败"
fi
#配置nginx虚拟主机
if [ -f $vhost/$domain ]
then
echo "虚拟主机配置文件已存在,nginx配置虚拟主机停止"
exit
else
/bin/cp $confdir/vhost.conf $vhost/$domain.conf
sed -i "s/domain/$domain/g" $vhost/$domain.conf
fi
if [[ $? -eq 0 ]]
then
echo "vhost配置文件已生成"
else
echo "vhost配置文件生成失败"
fi
#nginx检测配置文件
/usr/local/nginx/sbin/nginx -t
if [[ $? -eq 0 ]]
then
/etc/init.d/nginx reload
echo "重启nginx完成"
echo "项目访问URL: $domain"
else
echo "配置文件出现出错,请检查"
fi
PS:
# pwd
authz-db = ../../conf/authz
总用量 16
-rw-r--r-- 1 root root 1106 10月 21 10:15 authz
-rw-r--r-- 1 root root 341 10月 21 08:37 passwd
-rw-r--r-- 1 root root 191 10月 21 08:22 post-commit
-rw-r--r-- 1 root root 2337 10月 20 16:34 svnserve.conf
钩子(sync是通用账户,钩子专用):
# cat post-commit
#!/bin/sh
#export LANG="zh_CN.UTF-8"
export LANG="en_US.UTF-8"
SVN=/usr/bin/svn
WEB=/data/htdocs/domain
$SVN update $WEB --no-auth-cache --non-interactive --username "sync" --password "sync"
由于svn第一次检索需要认证,如果不人工输入yes,就不会checkout,所以需要更改/root/.subversion/servers,将[global]下的store-plaintext-passwords=no的注释去掉,或者直接添加如下
# vim /root/.subversion/servers
[global]
store-plaintext-passwords = no
这样就没有任何提示,直接checkout,脚本全部自动完成
脚本内容:
read -p "仓库名称:" domain
#domain=$1
# SVN仓库路径
svndir=/svn
# SVN配置文件路径
confdir=/svn/conf
# web目录
wwwroot=/data/htdocs
#nginx虚拟主机目录
vhost=/usr/local/nginx/conf/vhost
#创建SVN仓库
if [ -d $svndir/$domain ]
then
echo "仓库已存在"
exit
else
/usr/bin/svnadmin create $svndir/$domain
echo "仓库创建完成"
fi
#拷贝配置文件
/bin/cp $confdir/svnserve.conf $svndir/$domain/conf/svnserve.conf
if [[ $? -eq 0 ]]
then
echo "拷贝配置文件完成"
else
echo "拷贝配置文件失败"
exit
fi
#配置钩子,checkout
if [ -d $wwwroot/$domain ]
then
echo "网站目录已存在,钩子配置停止"
exit
else
/bin/cp $confdir/post-commit $svndir/$domain/hooks
/bin/sed -i "s/domain/$domain/g" $svndir/$domain/hooks/post-commit
/bin/chmod +x /$svndir/$domain/hooks/post-commit
echo "钩子配置完成"
fi
/usr/bin/svn co --username=sync --password sync svn://localhost/$domain $wwwroot/$domain
if [[ $? -eq 0 ]]
then
echo "SVN检索完成"
else
echo "SVN检索失败"
fi
#配置nginx虚拟主机
if [ -f $vhost/$domain ]
then
echo "虚拟主机配置文件已存在,nginx配置虚拟主机停止"
exit
else
/bin/cp $confdir/vhost.conf $vhost/$domain.conf
sed -i "s/domain/$domain/g" $vhost/$domain.conf
fi
if [[ $? -eq 0 ]]
then
echo "vhost配置文件已生成"
else
echo "vhost配置文件生成失败"
fi
#nginx检测配置文件
/usr/local/nginx/sbin/nginx -t
if [[ $? -eq 0 ]]
then
/etc/init.d/nginx reload
echo "重启nginx完成"
echo "项目访问URL: $domain"
else
echo "配置文件出现出错,请检查"
fi
PS:
svn用户权限统一管理(所有项目全调用/svn/conf下的authz和passwd)
# pwd
/svn/conf
# cat svnserve.conf |grep conf
password-db = ../../conf/passwdauthz-db = ../../conf/authz
总用量 16
-rw-r--r-- 1 root root 1106 10月 21 10:15 authz
-rw-r--r-- 1 root root 341 10月 21 08:37 passwd
-rw-r--r-- 1 root root 191 10月 21 08:22 post-commit
-rw-r--r-- 1 root root 2337 10月 20 16:34 svnserve.conf
钩子(sync是通用账户,钩子专用):
# cat post-commit
#!/bin/sh
#export LANG="zh_CN.UTF-8"
export LANG="en_US.UTF-8"
SVN=/usr/bin/svn
WEB=/data/htdocs/domain
$SVN update $WEB --no-auth-cache --non-interactive --username "sync" --password "sync"
由于svn第一次检索需要认证,如果不人工输入yes,就不会checkout,所以需要更改/root/.subversion/servers,将[global]下的store-plaintext-passwords=no的注释去掉,或者直接添加如下
# vim /root/.subversion/servers
[global]
store-plaintext-passwords = no
这样就没有任何提示,直接checkout,脚本全部自动完成