释放双眼,带上耳机,听听看~!
没事搞了个脚本,一键安装svn带http访问
系统是centos6.5
下面直接贴上脚本内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 1#!/bin/bash
2#Author: charlie.cen
3#Email: cenhuqing@gmail.com
4#Create_time: 2015-04-29
5
6#定义安装的包
7pkg="httpd subversion mod_dav_svn"
8#定义仓库路径
9repo_path=/opt/svn
10#定义仓库名
11read -p "Please enter your repo name: " repo
12#定义日志文件
13log="/tmp/install_svn.log"
14
15#安装包
16for i in ${pkg}
17do
18 rpm -qa |grep $i >> $log
19 if [ $? -eq 0 ]
20 then
21 echo "$i was already installed." >> $log
22 else
23 yum install -y $i > /dev/null 2>&1
24 echo "$i is now installed." >> $log
25 fi
26done
27
28
29#创建仓库
30if [ -e $repo_path -a -d $repo_path ]
31then
32 svnadmin create $repo_path/$repo && echo "$repo create successful" >> $log
33else
34 mkdir $repo_path && svnadmin create $repo_path/$repo && echo "$repo_path and $repo create successful." >> $log
35fi
36
37#修改svn配置
38sed -i 's/^# anon-access = read/anon-access = none/' $repo_path/$repo/conf/svnserve.conf
39sed -i 's/^# auth-access = write/auth-access = write/' $repo_path/$repo/conf/svnserve.conf
40sed -i 's/^# password-db = passwd/password-db = passwd/' $repo_path/$repo/conf/svnserve.conf
41sed -i 's/^# authz-db = authz/authz-db = authz/' $repo_path/$repo/conf/svnserve.conf
42echo "svnserve conf file modify already." >> $log
43
44#添加svn用户
45echo -n "Enter your name access http svn: "
46read name
47echo -n "Enter your passwd access http svn: "
48read passwd
49
50echo "$name = $passwd" >> $repo_path/$repo/conf/passwd
51echo "$name $passwd write on passwd file." >> $log
52echo "admin = $name" >> $repo_path/$repo/conf/authz
53echo -e "[$repo:/]\n@admin = rw" >> $repo_path/$repo/conf/authz
54echo "$name user write on authz file." >> $log
55
56#密码文件生成httppasswd文件
57#egrep -v '^#|^$|^\[' $repo_path/$repo/conf/passwd |while read line
58#do
59 #username=`echo $line |cut -d"=" -f1`
60 #password=`echo $line |cut -d"=" -f1`
61# if [ -n p1 ] && [ -f p1 ]
62# then
63# htpasswd -b p1 ${username} ${password}
64# else
65# htpasswd -bc p1 ${username} ${password}
66# fi
67#done
68if [ -n $repo_path/$repo/conf/webpasswd ] && [ -f $repo_path/$repo/conf/webpasswd ]
69then
70 htpasswd -b $repo_path/$repo/conf/webpasswd $name $passwd
71else
72 htpasswd -bc $repo_path/$repo/conf/webpasswd $name $passwd
73fi
74echo "webpasswd file create already." >> $log
75
76
77#配置apache
78ip=`ifconfig eth0 |awk 'NR==2{print $2}' |awk -F: '{print $2}'`
79httpd_conf="/etc/httpd/conf/httpd.conf"
80grep "^ServerName $ip:80" $httpd_conf && echo "ServerName config in $httpd_conf" >> $log ||echo "ServerName $ip:80" >> $httpd_conf
81
82http_conf="/etc/httpd/conf.d/subversion.conf"
83http_dir="/etc/httpd/conf.d"
84dir=`basename $repo_path`
85
86if [ -e $http_conf -a -f $http_conf ]
87then
88 echo "$http_conf was exist" >> $log
89 cat >> $http_conf << EOF
90<Location /$dir>
91DAV svn
92SVNParentPath $repo_path
93AuthType Basic
94AuthName "Subversion repository"
95AuthUserFile $repo_path/$repo/conf/webpasswd
96Require valid-user
97AuthzSVNAccessFile $repo_path/$repo/conf/authz
98</Location>
99EOF
100else
101 echo "$http_conf was not exist" >> $log
102 cat >> $http_conf << EOF
103LoadModule dav_svn_module modules/mod_dav_svn.so
104LoadModule authz_svn_module modules/mod_authz_svn.so
105<Location /$dir>
106DAV svn
107SVNParentPath $repo_path
108AuthType Basic
109AuthName "Subversion repository"
110AuthUserFile $repo_path/$repo/conf/webpasswd
111Require valid-user
112AuthzSVNAccessFile $repo_path/$repo/conf/authz
113</Location>
114EOF
115fi
116
117
118
119#启动svn服务
120num=`ps -ef |grep svnserve |grep -v grep |wc -l`
121if [ ${num} == 1 ]
122then
123 pkill svnserve
124else
125 svnserve -d -r $repo_path && echo "svnserve service was started." >> $log || echo "svnserve service not started." >> $log
126fi
127
128#启动httpd
129/etc/init.d/httpd configtest && /etc/init.d/httpd restart || echo "httpd config file is problem." >> $log
130