在Linux(CentOS 6.6)服务器上安装并配置基于Apache的SVN服务器

 #!/bin/bash
#
# 在Linux(CentOS 6.6)服务器上安装并配置基于Apache的SVN服务器:
#
# 、安装服务
# 、创建svn版本库
# 、创建svn用户
# 、配置svn权限
# 、配置http访问
# #
# 、安装服务
# # 1.1、安装程序包:subversion httpd mod_dav_svn yum install subversion httpd mod_dav_svn -y >> $.log
if [[ $? != ]]
then
echo "安装服务失败,停止svn部署"
exit
fi #
# 、创建svn版本库
# # 2.1、定义svn版本库存放目录
svn_path=/svn
# 2.2、创建svn版本库存放目录
mkdir -p $svn_path
# 2.3、定义要创建版本库的名称
repo_name=mysvn5
# 2.4、创建新的版本库
if [[ -d $svn_path/$repo_name ]]
then
echo "版本库 $repo_name 已经存在"
exit
fi
svnadmin create $svn_path/$repo_name
# 2.5、配置svn版本库的属主属组为http服务的启动用户
chown apache.apache -R $svn_path
# 2.6、确认新创建的svn版本库已经生成,且文件属主属组正确
ls -l $svn_path/$repo_name >> $.log #
# 、创建svn用户
# # 3.1、创建svn管理员账号
admin_passwd=$(< /dev/urandom tr -dc _A-Z-a-z-- | head -c9)
htpasswd -c -b -m $svn_path/$repo_name/conf/passwd admin $admin_passwd
echo "$repo_name 版本库的管理员账号为 admin ,密码是 $admin_passwd " |tee -a $.log # 3.2、创建svn具有读写权限的账号
rw_user_passwd=$(< /dev/urandom tr -dc _A-Z-a-z-- | head -c9)
htpasswd -b -m $svn_path/$repo_name/conf/passwd rw_user $rw_user_passwd
echo "$repo_name 版本库的读写账号为 rw_user ,密码是 $rw_user_passwd " |tee -a $.log # 3.3、创建svn具有只读权限的账号
ro_user_passwd=$(< /dev/urandom tr -dc _A-Z-a-z-- | head -c9)
htpasswd -b -m $svn_path/$repo_name/conf/passwd ro_user $ro_user_passwd
echo "$repo_name 版本库的只读账号为 ro_user ,密码是 $ro_user_passwd " |tee -a $.log #
# 、配置svn权限
# # 4.1、设置权限节点
echo "[$repo_name:/]" >>$svn_path/$repo_name/conf/authz
# 4.2、配置管理员账号有“读写”权限
echo "admin = rw" >>$svn_path/$repo_name/conf/authz
# 4.3、配置读写账号有“读写”权限
echo "rw_user = rw" >>$svn_path/$repo_name/conf/authz
# 4.4、配置只读账号有“只读”权限
echo "ro_user = r" >>$svn_path/$repo_name/conf/authz #
# 、配置http访问
# echo '<Location /svn/'$repo_name'>' >> /etc/httpd/conf.d/subversion.conf
# 定义svn类型的http服务,会调用dav_svn_module
echo ' DAV svn' >> /etc/httpd/conf.d/subversion.conf
# svn版本库目录
echo ' SVNPath '$svn_path'/'$repo_name'' >> /etc/httpd/conf.d/subversion.conf
# svn访问权限的配置文件
echo ' AuthzSVNAccessFile '$svn_path'/'$repo_name'/conf/authz' >> /etc/httpd/conf.d/subversion.conf
# svn使用http基本验证方式验证账号身份
echo ' AuthType Basic' >> /etc/httpd/conf.d/subversion.conf
# http基本验证的提示信息
echo ' AuthName "Authorization repot SVN"' >> /etc/httpd/conf.d/subversion.conf
# svn账号配置文件,包含加密后的密码信息
echo ' AuthUserFile '$svn_path'/'$repo_name'/conf/passwd' >> /etc/httpd/conf.d/subversion.conf
# 仅允许通过验证的用户访问svn
echo ' Require valid-user' >> /etc/httpd/conf.d/subversion.conf
echo '</Location>' >> /etc/httpd/conf.d/subversion.conf # 重启http服务
/etc/init.d/httpd restart
# 设置http服务开机启动
chkconfig httpd on
# 在防火墙上开放http服务
iptables -I INPUT -p tcp --dport -m state --state NEW -j ACCEPT
/etc/init.d/iptables save
# 关闭selinux
setenforce #
# 、提交代码时必须写注释,且不能少于10个字符;允许修改注释
# cp $svn_path/$repo_name/hooks/pre-commit.tmpl $svn_path/$repo_name/hooks/pre-commit sed -i '75a LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c)\nif [ "$LOGMSG" -lt 10 ]; then\necho -e "\n 提交文件时必须添加注释,提交中止."1>&2\nexit 1\nfi' $svn_path/$repo_name/hooks/pre-commit sed -i 's/^commit-access-control.pl/#commit-access-control.pl/' $svn_path/$repo_name/hooks/pre-commit chmod +x $svn_path/$repo_name/hooks/pre-commit cp $svn_path/$repo_name/hooks/pre-revprop-change.tmpl $svn_path/$repo_name/hooks/pre-revprop-change chmod +x $svn_path/$repo_name/hooks/pre-revprop-change
上一篇:Tomcat服务器常用配置和HTTP简介


下一篇:Oracle ROWNUM用法和分页查询总结(转)