-
Notifications
You must be signed in to change notification settings - Fork 1
/
svnbackup-create_repo.sh
executable file
·170 lines (135 loc) · 3.89 KB
/
svnbackup-create_repo.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
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# vim:ts=4:sw=4:et:
# script to create repository on repo server
# $Id: svnbackup-create_repo.sh 72 2010-09-29 18:26:42Z coolcold $
PROGNAME=$(basename $0)
CONFFILE_DEF=/etc/svnbackup.conf
print_usage() {
echo "Usage: $PROGNAME [-c <config file path>] -H <hostname>"
echo " use -h to show this help"
}
print_help() {
echo "$PROGNAME"
echo ""
print_usage
echo ""
echo "This will create subversion repository for <hostname>"
}
if [ -z $1 ];then
print_help
exit 1
fi
# parsing arguments
while getopts ":hc:H:" Option; do
case $Option in
h)
print_help
exit 0
;;
c)
CONFFILE=${OPTARG}
;;
H)
REPOHOST=${OPTARG}
;;
*)
print_help
exit 0
;;
esac
done
shift $(($OPTIND - 1))
# end of arguments parsing
if [ -z "$CONFFILE" ];then CONFFILE=${CONFFILE_DEF};fi
if [ ! -f $CONFFILE ];then
echo "configuration file $CONFFILE doesn't exist. Check path you've specified?"
exit 1
fi
if ! . $CONFFILE;then
echo "cannot include config file $CONFFILE . Check permissions?"
exit 2
fi
if [ -z $REPOHOST ];then
echo "hostname was not specified"
echo ""
print_help
exit 1
fi
#checking for username repository will be accessed by
if [ -z $SVNUSER ];then
echo "username for subversion repository rw access was not specified, set SVNUSER variable in config $CONFFILE"
exit 1
fi
#checking for directory owner in user:group format repository will be owned by
if [ -z $REPOOWNED ];then
echo "repository dir owner was not specified, specify REPOOWNED variable in config $CONFFILE . Format is uid:gid acceptable by chown"
exit 1
fi
# if INSTALLPCHOOK = YES post-commit template should be copied into hooks, checking is path specified and exist
if [ "x${INSTALLPCHOOK}" == "xYES" ];then
if [ -z ${PCHOOK_TMPL} ];then
echo "INSTALLPCHOOK option is set to ${INSTALLPCHOOK} , but PCHOOK_TMPL is empty, specify variable value in config file ${CONFFILE}"
exit 1
fi
#checking for existance
if [ ! -r "${PCHOOK_TMPL}" ];then
echo "Template file ${PCHOOK_TMPL} is not readable"
exit 1
fi
fi
if [ -z $REPOSPATH ];then echo "subversion repositories path variable REPOSPATH is not set, check your config $CONFFILE";exit 2;fi
if ! which svn >/dev/null;then echo "subversion not found in your PATH, consider installing subversion"; exit 2;fi
REPOPATH="${REPOSPATH}${REPOHOST}"
#does destination folder already exist?
if [ -d $REPOPATH ];then
echo "Directory $REPOPATH already exist, exiting"
exit 1
fi
CMD="svnadmin create --fs-type fsfs $REPOPATH"
echo "the next command will be executed"
echo "$CMD"
repopasswd=$(openssl passwd .)
echo "password for repository $1 will be ${repopasswd} "
echo "You need to paste it on the remote host $REPOHOST"
repo_data=$($CMD 2>&1)
repo_res=$?
if [ $repo_res -ne 0 ];then
echo "failed to create repository for $REPOHOST in $REPOPATH"
echo "message is:"
echo "$repo_data"
exit 2
fi
#generating configs
cat <<EOF>"${REPOPATH}/conf/authz"
[/]
${SVNUSER} = rw
EOF
cat<<EOF>"${REPOPATH}/conf/passwd"
[users]
${SVNUSER} = ${repopasswd}
EOF
cat<<EOF>"${REPOPATH}/conf/svnserve.conf"
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = ${REPOHOST} repository
EOF
#installing hook
if [ "x${INSTALLPCHOOK}" == "xYES" ];then
PCHOOKPATH="${REPOPATH}/hooks/post-commit"
echo "installing post-commit hook into ${PCHOOKPATH} ..."
PCHOOK_CONTENT=$(sed "s/BHOST_TEMPLATE/${REPOHOST}/" "${PCHOOK_TMPL}")
if ! echo "${PCHOOK_CONTENT}"|grep -q "${REPOHOST}";then
#failed
echo "template update failed, post-commit hook won't be installed"
else
echo "${PCHOOK_CONTENT}" > "${PCHOOKPATH}"
chmod +x "${PCHOOKPATH}"
fi
else
echo "skipping installation of post-commit hook..."
fi
chown -R "${REPOOWNED}" ${REPOPATH}
echo "done"