-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·302 lines (260 loc) · 11.3 KB
/
setup.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#/bin/bash
#Setting up gitolite, gitweb, mantisbt
#create the git user
GIT_USER="git"
GIT_HOME="/home/git"
WEB_DIR="/var/www"
MANTISBT="mantisbt-1.2.19"
MBT_ADMIN="[email protected]"
MBT_WEBMASTER="[email protected]"
MBT_REPLY="[email protected]"
MBT_BOUNCE="[email protected]"
CUSER=$( whoami )
#login method to be used for gitweb
#valid options: none, basic
#GITWEB_LOGIN="basic"
GITWEB_LOGIN="none"
#GITWEB_SSL="YES"
GITWEB_SSL="NO"
GIT_TMP=$( pwd )
if [ $1 == "install" ]; then
if id -u "${GIT_USER}" >/dev/null 2>&1; then
echo "Not creating user ${GIT_USER}; already exists"
else
echo "Creating git user ${GIT_USER}"
sudo adduser --disabled-password --home ${GIT_HOME} ${GIT_USER}
fi
if [ ! -d ${GIT_HOME}/bin ]; then
echo "Making bin directory"
sudo -u ${GIT_USER} -g ${GIT_USER} mkdir ${GIT_HOME}/bin
fi
if [ ! -d ${GIT_TMP}/gitolite ]; then
echo "Cloning gitolite repository"
git clone git://github.com/sitaramc/gitolite ${GIT_TMP}/gitolite
sudo rm -r ${GIT_HOME}/gitolite
fi
cd ${GIT_HOME}
if [ ! -d ${GIT_HOME}/gitolite ]; then
echo "Copying gitolite repository to git user"
sudo cp -r ${GIT_TMP}/gitolite ${GIT_HOME}/gitolite
sudo chown -R ${GIT_USER}:${GIT_USER} ${GIT_HOME}/gitolite
sudo -H -u ${GIT_USER} -g ${GIT_USER} ${GIT_HOME}/gitolite/install -ln ${GIT_HOME}/bin
sudo ln -s ${GIT_HOME}/bin/gitolite /usr/bin/gitolite
fi
if [ ! -e ${GIT_HOME}/admin.pub ]; then
echo "Copying admin public key to user ${GIT_USER}"
sudo cp ~/.ssh/id_rsa.pub ${GIT_HOME}/admin.pub
sudo chown ${GIT_USER}:${GIT_USER} ${GIT_HOME}/admin.pub
cd ${GIT_HOME}
echo "sudo -H -u ${GIT_USER} -g ${GIT_USER} gitolite setup -pk ${GIT_HOME}/admin.pub"
sudo -H -u ${GIT_USER} -g ${GIT_USER} gitolite setup -pk ${GIT_HOME}/admin.pub
fi
echo "Beginning setup of gitweb"
#only user and group need any access at all to the git user home directory
#sudo chmod -R o-wrx ${GIT_HOME}
sudo chmod g+r ${GIT_HOME}/projects.list
sudo chmod g+rx ${GIT_HOME}/repositories
cd ${GIT_HOME}
if [ ! -d ${GIT_TMP}/git ]; then
echo "Cloning git repository"
git clone git://git.kernel.org/pub/scm/git/git.git ${GIT_TMP}/git
sudo rm -r ${GIT_HOME}/git
fi
if [ ! -d ${GIT_HOME}/git ]; then
echo "Copying git repository"
sudo cp -r ${GIT_TMP}/git ${GIT_HOME}/git
sudo chown -R ${GIT_USER}:${GIT_USER} ${GIT_HOME}/git
fi
GIT_LOCATION=$( which git )
GIT_LOCATION=${GIT_LOCATION%/*}
echo "Editing .gitolite.rc"
sudo sed -i.bak 's/GIT_CONFIG_KEYS => \x27\x27/GIT_CONFIG_KEYS => \x27core.sharedRepository\x27/' ${GIT_HOME}/.gitolite.rc
if [ ! -d ${GIT_TMP}/gitolite-admin ]; then
echo "Cloning gitolite-admin repository"
git clone git@localhost:gitolite-admin.git ${GIT_TMP}/gitolite-admin
cd ${GIT_TMP}/gitolite-admin
sudo sed -i.bak '/repo testing/ a\ config core.sharedRepository = 0640' conf/gitolite.conf
git add conf/gitolite.conf
git commit -m "Add sharedRepository setting to testing repository"
git push origin master
fi
echo "Fixing testing.git permissions"
sudo find ${GIT_HOME}/repositories/testing.git -type f -exec chmod g+r {} \;
sudo find ${GIT_HOME}/repositories/testing.git -type d -exec chmod g+rx {} \;
sudo chmod g+x ${GIT_HOME}/.gitolite
sudo chmod g+rwx ${GIT_HOME}/.gitolite/logs
sudo chmod g+rx ${GIT_HOME}/.gitolite/conf
sudo chmod -R g+r ${GIT_HOME}/.gitolite/conf
sudo chmod -R g+rw ${GIT_HOME}/.gitolite/logs
if [ ! -d ${GIT_TMP}/testing ]; then
echo "Cloning test repository"
git clone git@localhost:testing.git ${GIT_TMP}/testing
cd ${GIT_TMP}/testing
touch first_file.txt
git add first_file.txt
git commit -m "First commit to test repository"
git push origin master
echo "Put some data in the file" >> first_file.txt
git add first_file.txt
git commit -m "Add some data to the first file"
git push origin master
fi
cd ~
echo "GIT location: ${GIT_LOCATION}"
cd ${GIT_HOME}/git
sudo -u ${GIT_USER} make \
bindir=${GIT_LOCATION} \
GITWEB_LIST=${GIT_HOME}/projects.list \
GITWEB_PROJECTROOT=${GIT_HOME}/repositories \
GITWEB_CONFIG_SYSTEM=${GIT_HOME}/gitwebsettings.conf \
clean gitweb
cd ..
if [ ! -d gitweb ]; then
sudo -u ${GIT_USER} mkdir gitweb
sudo -u ${GIT_USER} mkdir gitweb/static
fi
sudo -u ${GIT_USER} mv git/gitweb/gitweb.cgi gitweb/
sudo -u ${GIT_USER} cp -r git/gitweb/static/ gitweb/
if [ ! -e ${GIT_HOME}/gitwebsettings.conf ]; then
sudo -u ${GIT_USER} touch $GIT_HOME/gitwebsettings.conf
fi
if [ ! -e ${GIT_HOME}/gitweb.conf ]; then
echo "Making gitweb.conf"
sudo touch ${GIT_HOME}/gitweb.conf
sudo chown ${CUSER} ${GIT_HOME}/gitweb.conf
echo "Alias /gitweb ${GIT_HOME}/gitweb" >> ${GIT_HOME}/gitweb.conf
echo "" >> ${GIT_HOME}/gitweb.conf
if [ ${GITWEB_SSL} == "YES" ]; then
echo "<Location /gitweb>" >> ${GIT_HOME}/gitweb.conf
echo " SSLRequireSSL" >> ${GIT_HOME}/gitweb.conf
echo "</Location>" >> ${GIT_HOME}/gitweb.conf
echo "" >> ${GIT_HOME}/gitweb.conf
echo "<Location /mantisbt>" >> ${GIT_HOME}/gitweb.conf
echo " SSLRequireSSL" >> ${GIT_HOME}/gitweb.conf
echo "</Location>" >> ${GIT_HOME}/gitweb.conf
echo "" >> ${GIT_HOME}/gitweb.conf
fi
echo "<Directory ${GIT_HOME}/gitweb>" >> ${GIT_HOME}/gitweb.conf
echo " Options +FollowSymLinks +ExecCGI" >> ${GIT_HOME}/gitweb.conf
echo " AddHandler cgi-script .cgi" >> ${GIT_HOME}/gitweb.conf
if [ ${GITWEB_LOGIN} == "basic" ]; then
sudo rm ${GIT_HOME}/gitweb_pw
echo "Creating password for user ${CUSER} on gitweb"
sudo htpasswd -c ${GIT_HOME}/gitweb_pw ${CUSER}
sudo chown ${GIT_USER}:${GIT_USER} ${GIT_HOME}/gitweb_pw
sudo chmod 0640 ${GIT_HOME}/gitweb_pw
echo " AuthType Basic" >> ${GIT_HOME}/gitweb.conf
echo " AuthName \"Authorization required\"" >> ${GIT_HOME}/gitweb.conf
echo " AuthBasicProvider file" >> ${GIT_HOME}/gitweb.conf
echo " AuthUserFile ${GIT_HOME}/gitweb_pw" >> ${GIT_HOME}/gitweb.conf
echo " Require valid-user " >> ${GIT_HOME}/gitweb.conf
elif [ ${GITWEB_LOGIN} == "none" ]; then
echo "No authentication specified for gitweb"
else
echo "ERROR: Invalid gitweb login option specified"
sudo rm ${GIT_HOME}/gitweb.conf
exit
fi
echo "</Directory>" >> ${GIT_HOME}/gitweb.conf
echo "" >> ${GIT_HOME}/gitweb.conf
sudo chown ${GIT_USER} ${GIT_HOME}/gitweb.conf
fi
if [ ! -e /etc/apache2/conf.d/gitweb.conf ]; then
echo "Copying gitweb stuff to apache2"
sudo ln -s ${GIT_HOME}/gitweb.conf /etc/apache2/conf.d/gitweb.conf
sudo ln -s ${GIT_HOME}/gitweb/gitweb.cgi ${GIT_HOME}/gitweb/index.cgi
sudo a2enmod cgi
sudo usermod -a -G git www-data
fi
#sudo chmod -R o-wrx ${GIT_HOME}
sudo service apache2 restart
echo "Installing mantisbt"
if [ ! -e ${GIT_TMP}/${MANTISBT}.zip ]; then
echo "Downloading ${MANTISBT}"
wget http://sourceforge.net/projects/mantisbt/files/latest/download?source=files -O ${MANTISBT}.zip
sudo rm -r ${GIT_HOME}/${MANTISBT}
fi
if [ ! -d ${GIT_HOME}/${MANTISBT} ]; then
echo "Extracting mantisbt"
sudo unzip ${GIT_TMP}/${MANTISBT}.zip -d ${GIT_HOME} > /dev/null 2>&1
sudo chown -R ${GIT_USER}:${GIT_USER} ${GIT_HOME}/${MANTISBT}
sudo chmod -R g+rw ${GIT_HOME}/${MANTISBT}
sudo chmod g+x ${GIT_HOME}/${MANTISBT}
sudo ln -s ${GIT_HOME}/${MANTISBT} ${WEB_DIR}/mantisbt
echo "Point a broweser to the mantisbt part of the webserver and do the configuration"
read -p "Press any key to continue... " -n1 -s
echo ""
sudo cp ${GIT_HOME}/${MANTISBT}/config_inc.php ${GIT_TMP}/config_inc.php
sudo chown ${CUSER}:${CUSER} ${GIT_TMP}/config_inc.php
sudo tail -n +43 ${GIT_HOME}/${MANTISBT}/config_inc.php.sample >> ${GIT_TMP}/config_inc.php
sudo sed -i.bak "s/administrator_email\([^$]*\)[email protected]/administrator_email\1${MBT_ADMIN}/g" ${GIT_TMP}/config_inc.php
sudo sed -i.bak "s/webmaster_email\([^$]*\)[email protected]/webmaster_email\1${MBT_WEBMASTER}/g" ${GIT_TMP}/config_inc.php
sudo sed -i.bak "s/from_email\([^$]*\)[email protected]/from_email\1${MBT_REPLY}/g" ${GIT_TMP}/config_inc.php
sudo sed -i.bak "s/return_path_email\([^$]*\)[email protected]/return_path_email\1${MBT_BOUNCE}/g" ${GIT_TMP}/config_inc.php
sudo cp ${GIT_TMP}/config_inc.php ${GIT_HOME}/${MANTISBT}/config_inc.php
sudo chown ${GIT_USER}:${GIT_USER} ${GIT_HOME}/${MANTISBT}/config_inc.php
sudo rm -r ${GIT_HOME}/${MANTISBT}/admin
fi
echo "Installing mantisbt source integration"
if [ ! -d ${GIT_TMP}/source-integration ]; then
echo "Downloading mantisbt source-integration"
git clone https://github.com/mantisbt-plugins/source-integration.git ${GIT_TMP}/source-integration
fi
echo "Copying source integration files"
sudo cp -r ${GIT_TMP}/source-integration/Source ${GIT_HOME}/${MANTISBT}/plugins
sudo cp -r ${GIT_TMP}/source-integration/SourceGitweb ${GIT_HOME}/${MANTISBT}/plugins
echo "Login to mantisbt"
echo "Go to Manage Plugins"
echo "Click Install in the row with Source Control Integration"
echo "Click Install in the row with Gitweb Integration"
echo "Click on the Source Control Integration link"
echo "Enter the following line into the API key field"
MANTISBT_API_KEY=$( openssl rand -hex 12 )
echo ${MANTISBT_API_KEY}MANTISBT_API_KEY=$( openssl rand -hex 12 )
echo ${MANTISBT_API_KEY}
MANTISBT_DBLOCATE=$( sudo sed -n "s/.*g_hostname.*=.*\x27\(.*\)\x27.*/\1/p" ${GIT_HOME}/${MANTISBT}/config_inc.php )
MANTISBT_DBTYPE=$( sudo sed -n "s/.*g_db_type.*=.*\x27\(.*\)\x27.*/\1/p" ${GIT_HOME}/${MANTISBT}/config_inc.php )
MANTISBT_DBNAME=$( sudo sed -n "s/.*g_database_name.*=.*\x27\(.*\)\x27.*/\1/p" ${GIT_HOME}/${MANTISBT}/config_inc.php )
MANTISBT_USER=$( sudo sed -n "s/.*g_db_username.*=.*\x27\(.*\)\x27.*/\1/p" ${GIT_HOME}/${MANTISBT}/config_inc.php )
MANTISBT_UPASS=$( sudo sed -n "s/.*g_db_password.*=.*\x27\(.*\)\x27.*/\1/p" ${GIT_HOME}/${MANTISBT}/config_inc.php )
#check for the key in table mantis_config_table
#config_id = plugin_Source_api_key
#value = ${MANTISBT_API_KEY}
#mysql -D bugtracker -N -s -u mantis -pmantis -e "SELECT * FROM mantis_config_table WHERE config_id=\"plugin_Source_api_key\" AND value=\"041fbbcf61f10862cf254faf\";"
MANTISBT_API_KEY_SET=$( mysql -D ${MANTISBT_DBNAME} -N -s -u ${MANTISBT_USER} -p${MANTISBT_UPASS} -e "SELECT * FROM mantis_config_table WHERE config_id=\"plugin_Source_api_key\" AND value=\"${MANTISBT_API_KEY}\";" | wc -l );
while [ $MANTISBT_API_KEY_SET == 0 ]
do
echo "ERROR: API_KEY NOT ENTERED CORRECTLY. PLEASE TRY AGAIN"
echo "Login to mantisbt"
echo "Go to Manage Plugins"
echo "Click Install in the row with Source Control Integration"
echo "Click Install in the row with Gitweb Integration"
echo "Click on the Source Control Integration link"
echo "Enter the following line into the API key field"
MANTISBT_API_KEY=$( openssl rand -hex 12 )
echo ${MANTISBT_API_KEY}
echo "Click Update Configuration"
read -p "Press any key to continue... " -n1 -s
echo ""
MANTISBT_API_KEY_SET=$( mysql -D ${MANTISBT_DBNAME} -N -s -u ${MANTISBT_USER} -p${MANTISBT_UPASS} -e "SELECT * FROM mantis_config_table WHERE config_id=\"plugin_Source_api_key\" AND value=\"${MANTISBT_API_KEY}\";" | wc -l );
done
#thsi fi belongs to the end of the install if
fi
if [ $1 == "remove" ]; then
if [ -L ${WEB_DIR}/mantisbt ]; then
sudo rm ${WEB_DIR}/mantisbt
fi
if [ -L /etc/apache2/conf.d/gitweb.conf ]; then
echo "Removing gitweb stuff from apache2/conf.d"
sudo rm /etc/apache2/conf.d/gitweb.conf
sudo deluser www-data git
fi
if id -u "${GIT_USER}" >/dev/null 2>&1; then
echo "Removing user ${GIT_USER} and deleting home directory ${GIT_HOME}"
sudo deluser --remove-home ${GIT_USER}
sudo delgroup ${GIT_USER}
sudo rm /usr/bin/gitolite
rm -rf ${GIT_TMP}/testing
rm -rf ${GIT_TMP}/gitolite-admin
fi
fi