快速创建svn脚本

#/bin/bash
# auto set svn httpd
# author:liubaixun
# email:[email protected]
# subversion (SVN服务器)
# httpd mod_dav_svn mod_perl (用于支持WEB方式管理SVN服务器)
# ntsysv vim-enhanced (可选)
# yum install subversion mysql-server httpd mod_dav_svn mod_perl sendmail wget gcc-c++ make unzip perl* ntsysv vim-enhanced

# will install base software
if [ "$1" = "0" ]; then
yum -y install subversion httpd
fi
# set evn name
# svn 用于存储SVN所有文件
svnDir="/database/svn"
# svn 的项目的名字
projectName="ralink"
svnWelcome="svn for $projectName"
# svn 的登录帐号和密码
svnGroup="admin"
svnName="admin"
svnPass="123456"
#读写权限: r w
# 说明:只有svnGroup用户组有根目录的读写权。
# r表示对该目录有读权限,w表示对该目录有写权限,rw表示对该目录有读写权限。
WriteRead=rw

# 1.新建一个目录用于存储SVN所有文件
rm -i $svnDir
mkdir -p $svnDir
# 2.新建一个版本仓库
svnadmin create $svnDir/$projectName
# 3.初始化版本仓库中的目录
# 建立临时目录
mkdir $projectName $projectName/trunk $projectName/tag $projectName/branch
# 初始化
svn import $projectName/ file:///$svnDir/$projectName -m "初始化SVN目录"
# 4.删除临时建立的目录
rm -rf $projectName

# 5.添加用户
echo "$svnName=$svnPass" >> $svnDir/$projectName/conf/passwd

# 6.修改访问策略
echo "[groups]" > $svnDir/$projectName/conf/authz
echo "$svnGroup = $svnName" >> $svnDir/$projectName/conf/authz
echo "[$projectName:/]" >> $svnDir/$projectName/conf/authz
echo "@$svnGroup = $WriteRead" >> $svnDir/$projectName/conf/authz
#最后一行的* =表示,除了上面设置了权限的用户组之外,其他任何人都被禁止访问本目录。这个很重要,一定要加上!
echo "* =" >> $svnDir/$projectName/conf/authz

# 7.修改svnserve.conf文件,让用户和策略配置升效.
sed -i "/anon-access/d"  $svnDir/$projectName/conf/svnserve.conf
sed -i "/auth-access/d"  $svnDir/$projectName/conf/svnserve.conf
sed -i "/password-db/d"  $svnDir/$projectName/conf/svnserve.conf
sed -i "/authz-db/d"  $svnDir/$projectName/conf/svnserve.conf
echo "anon-access = none" >> $svnDir/$projectName/conf/svnserve.conf
echo "auth-access = write" >> $svnDir/$projectName/conf/svnserve.conf
echo "password-db = $svnDir/$projectName/conf/passwd" >> $svnDir/$projectName/conf/svnserve.conf
echo "authz-db = $svnDir/$projectName/conf/authz" >> $svnDir/$projectName/conf/svnserve.conf

# 8. please test
# 启动服务器
# svnserve -d -r /home/svn
#注意:如果修改了svn配置,需要重启svn服务,步骤如下:
# ps -aux|grep svnserve
# kill -9 ID号
# svnserve -d -r /home/svn

# 9. 配置SVN服务器的HTTP支持
# 由于SVN服务器的密码是明文的,HTTP服务器不与支持,所以需要转换成HTTP支持的格式
# set pass by http
htpasswd -bc $svnDir/$projectName/conf/webpasswd $svnName $svnPass


# 10.修改http.conf
echo "<Location /$projectName>" >> /etc/httpd/conf/httpd.conf
echo " DAV svn" >> /etc/httpd/conf/httpd.conf
echo " SVNPath $svnDir/$projectName/" >> /etc/httpd/conf/httpd.conf
echo " AuthType Basic" >> /etc/httpd/conf/httpd.conf
echo " AuthName \"$svnWelcome\"" >> /etc/httpd/conf/httpd.conf
echo " AuthUserFile $svnDir/$projectName/conf/webpasswd" >> /etc/httpd/conf/httpd.conf
echo " AuthzSVNAccessFile $svnDir/$projectName/conf/authz" >> /etc/httpd/conf/httpd.conf
echo " Satisfy all" >> /etc/httpd/conf/httpd.conf
echo " Require valid-user" >> /etc/httpd/conf/httpd.conf
echo "</Location>" >> /etc/httpd/conf/httpd.conf

# 11.修改svn目录的属主为apache帐号
chown -R apache.apache $svnDir/$projectName/

# 12.重启httpd服务
/etc/init.d/httpd restart &
exit 0

你可能感兴趣的:(快速创建svn脚本)