forked from maicong/LNMP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svn.sh
158 lines (137 loc) · 4.71 KB
/
svn.sh
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
#
## Installing Subversion
## https://github.com/maicong/LNMP
## Usage: bash svn.sh
clear;
## 检查 root 权限
[ $(id -g) != "0" ] && die "Script must be run as root.";
echo "================================================================";
echo "Installing Subversion";
echo "https://github.com/maicong/LNMP";
echo "Usage: bash svn.sh";
echo "================================================================";
project='';
projectPath='';
webPath='';
username='';
password=`cat /dev/urandom | head -1 | md5sum | head -c 12`;
ipAddress=`ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\." | head -n 1`;
## 输入 IP 地址
function InputIP()
{
if [ "$ipAddress" == '' ]; then
echo '[Error] empty server ip.';
read -p '[Notice] Please input server ip:' ipAddress;
[ "$ipAddress" == '' ] && InputIP;
else
echo '[OK] Your server ip is:' && echo $ipAddress;
read -p '[Notice] This is your server ip? : (y/n)' confirmDM;
if [ "$confirmDM" == 'n' ]; then
ipAddress='';
InputIP;
elif [ "$confirmDM" != 'y' ]; then
InputIP;
fi;
fi;
}
## 输入 项目名称
function InputName()
{
if [ "$project" == '' ]; then
read -p '[Notice] Please input project name:' project;
[ "$project" == '' ] && InputName;
else
echo '[OK] Your project name is:' && echo $project;
read -p '[Notice] This is your project name? : (y/n)' confirmDM;
if [ "$confirmDM" == 'n' ]; then
project='';
InputName;
elif [ "$confirmDM" != 'y' ]; then
InputName;
fi;
fi;
projectPath="/var/svn/repos/${project}";
webPath="/home/wwwroot/${project}";
username="user-${project}";
[ -d "${projectPath}" ] && echo "[Error] ${project} is exist!" && project='' && InputName;
mkdir -p ${projectPath};
}
## 输入 WEB 目录
function InputWebPath()
{
if [ "$webPath" == '' ]; then
read -p '[Notice] Please input web directory:' webPath;
[ "$webPath" == '' ] && InputWebPath;
else
echo '[OK] Your web directory is:' && echo $webPath;
read -p '[Notice] This is your web directory? : (y/n)' confirmDM;
if [ "$confirmDM" == 'n' ]; then
webPath='';
InputWebPath;
elif [ "$confirmDM" != 'y' ]; then
InputWebPath;
fi;
fi;
[ -d "${webPath}/.svn/" ] && echo "[Error] ${webPath} is exist!" && webPath='' && InputWebPath;
}
## 安装 SVN
function InstallSVN()
{
[ $(rpm -qa subversion | wc -l) == "0" ] && yum install subversion -y;
svnadmin create ${projectPath};
cat >> ${projectPath}/conf/authz << EOF
[/]
${username} = rw
* =
EOF
cat >> ${projectPath}/conf/passwd << EOF
${username} = ${password}
EOF
svnserve="${projectPath}/conf/svnserve.conf";
sed -i "s@# anon-access@anon-access@" $svnserve;
sed -i "s@# auth-access@auth-access@" $svnserve;
sed -i "s@# password-db = passwd@password-db = ${projectPath}/conf/passwd@" $svnserve;
sed -i "s@# authz-db = authz@authz-db = ${projectPath}/conf/authz@" $svnserve;
cp ${projectPath}/hooks/post-commit.tmpl ${projectPath}/hooks/post-commit;
cat > ${projectPath}/hooks/post-commit << EOF
#!/bin/sh
export LANG=en_US.UTF-8
REPOS="\$1"
REV="\$2"
WEB_PATH=${webPath}
LOG_PATH=/tmp/svn_commit.log
SVN_PATH=/usr/bin/svn
SVN_REPOS=svn://localhost/repos/${project}
echo "nnn########## Commit " \`date "+%Y-%m-%d %H:%M:%S"\` '##################' >> \$LOG_PATH
echo \`whoami\`,\$REPOS,\$REV >> \$LOG_PATH
echo \`\$SVN_PATH checkout \$SVN_REPOS \$WEB_PATH --username "$username" --password "$password" --no-auth-cache >> \$LOG_PATH\`
chown -R www:www \$WEB_PATH
EOF
chmod 755 ${projectPath}/hooks/post-commit;
firewall-cmd --permanent --zone=public --add-port=3690/tcp;
firewall-cmd --reload;
systemctl enable svnserve.service
}
## 安装完成
function InstallCompleted()
{
status='';
systemctl restart svnserve.service && status='ok';
if [ "$status" == 'ok' ]; then
echo "================================================================";
echo -e "\033[42m [SVN] Install completed. \033[0m";
echo -e "\033[34m SVN URL: \033[0m svn://${ipAddress}/repos/${project}";
echo -e "\033[34m Username: \033[0m ${username}";
echo -e "\033[34m Password: \033[0m ${password}";
echo "================================================================";
else
echo -e "\033[41m [SVN] Sorry, Install Failed. \033[0m";
echo "Please contact us: https://github.com/maicong/LNMP/issues";
fi;
}
InputIP;
InputName;
InputWebPath;
InstallSVN;
InstallCompleted;