svn仓库创建脚本svncreate:
用法:/path/svncreate reposname
#!/bin/bash
svnroot='/opt/svnroot' #svn根目录
httpuser='apache' #httpd运行时用户
existrepos='repos1' #一个已存在的项目名称,记得根据需要修改
sedstr='reposname' #sed替换时的匹配字符串
currentdir=$(cd `dirname $0`; pwd) #获取脚本的路径
postci=$currentdir'/post-commit'
if [ -z $1 ]; then #项目名称是否作为参数给出
N=$currentdir/svncreate.sh
echo "Usage: $N reposname" >&2
exit 1
fi
if [ ! -f $postci ]; then #钩子脚本是否存在当前目录下
echo "Missing file $postci"
exit 1
fi
/usr/bin/svnadmin create $svnroot/$1 #创建svn仓库
alias cp='cp' #禁用centos复制的提示
cp $svnroot/$existrepos/conf/svnserve.conf $svnroot/$1/conf/svnserve.conf
cp $svnroot/$existrepos/conf/passwd $svnroot/$1/conf/passwd
cp $svnroot/$existrepos/conf/authz $svnroot/$1/conf/authz
chown -R ${httpuser} $svnroot/$1
cp $currentdir/post-commit $svnroot/$1/hooks/post-commit #钩子
sed -i "s/${sedstr}/$1/g" $svnroot/$1/hooks/post-commit #修改钩子文件
chmod a+x $svnroot/$1/hooks/post-commit #执行权限
alias cp='cp -i' #回复centos的复制提示
钩子hooks:post-commit
#!/bin/bash
SVN=/usr/bin/svn
project='reposname'
TODIR=/opt/www/$project
svnpass=123456
svnuser=testczk
if [ -d $TODIR ]; then
$SVN update svn://127.0.0.1/$project $TODIR --username $svnuser --password $svnpass --non-interactive
else
mkdir -p $TODIR
$SVN checkout svn://127.0.0.1/$project $TODIR --username $svnuser --password $svnpass --non-interactive
fi
阅读(2177) | 评论(0) | 转发(0) |