-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate.sh
executable file
·238 lines (220 loc) · 7.37 KB
/
update.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
#!/bin/bash
#
# update alminium
#
ALM_SRC_DIR=${ALM_HOME}/alminium
ALM_INSTALL_DIR=/opt/alminium
ALM_SUBDIR=${ALM_RELATIVE_URL_ROOT}
# 関数群
source ${ALM_SRC_DIR}/inst-script/functions
# start updating
echo $(date) - update ALMinium ...
#
# log
#
mkdir -p /var/log/alminium
mkdir -p /var/log/alminium/redmine
mkdir -p /var/log/alminium/apache2
chown -R www-data:www-data /var/log/alminium/redmine
chown -R root:adm /var/log/alminium/apache2
chmod 760 /var/log/alminium/*
#
# ALMinium's DB data
#
if [ ! -f ${ALM_HOME}/initialized ]; then
# 未初期化状態なので初期化を行う
while [ "$(db_test alminium)" = "" ]; do
echo "checking db connection..."
sleep 3
done
echo "successed to connect db."
# gem install for redmine_jenkins and db migration
BUNDLER=bundle
source ${ALM_SRC_DIR}/redmine/setup/setup-db
pushd ${ALM_INSTALL_DIR}
mv plugins-jenkins/* plugins/ 2>/dev/null
bundle install --path vendor/bundle \
--without development test postgresql sqlite xapian
bundle exec rake redmine:plugins:migrate \
RAILS_ENV=production NAME=redmine_jenkins
popd
touch ${ALM_HOME}/initialized
fi
echo "db service is ready."
#
# attachement files
#
if [ ! -f /opt/alminium/files/initialized ]; then
cd /opt/alminium && tar xzf ${ALM_HOME}/files.tar.gz
fi
echo "attachement files are ready."
#
# ALMinium's repo
#
if [ ! -f /var/opt/alminium/initialized ]; then
cd /var/opt && tar xzf ${ALM_HOME}/repo.tar.gz
fi
echo "repositories are ready."
# HOSTNAME
ALM_OLD_HOSTNAME=`cat /etc/opt/alminium/hostname`
if [ "${ALM_OLD_HOSTNAME}" != "${ALM_HOSTNAME}" ]; then
echo "changed hostname: [${ALM_OLD_HOSTNAME}] -> [${ALM_HOSTNAME}]"
cd /etc/opt/alminium
for FILE in $(ls redmine*.conf)
do
sed -i.old "s|ServerName ${ALM_OLD_HOSTNAME}|ServerName ${ALM_HOSTNAME}|" \
$FILE
done
echo ${ALM_HOSTNAME} > /etc/opt/alminium/hostname
fi
echo "HOSTNAME settings are ready."
echo "HOSTNAME is ${ALM_HOSTNAME} (old name is ${ALM_OLD_HOSTNAME})"
#
# RELATIVE_PATH
#
ALM_OLD_REL_PATH=`cat /etc/opt/alminium/relative_path`
if [ "`echo ${ALM_RELATIVE_URL_ROOT} | cut -c 1`" = "/" ]
then
ALM_NEW_REL_PATH=`echo ${ALM_RELATIVE_URL_ROOT} | cut -c 2-`
else
ALM_NEW_REL_PATH=${ALM_RELATIVE_URL_ROOT}
fi
# set old path and new path
if [ "${ALM_OLD_REL_PATH}" != "${ALM_NEW_REL_PATH}" ]
then
echo "changed relative path: [${ALM_OLD_REL_PATH}] -> [${ALM_NEW_REL_PATH}]"
if [ "${ALM_OLD_REL_PATH}" = "" ]
then
# case that non-rerative to rerative,
# ex.: http://localhost/projects/test
# ==> http://localhost/alminium/projects/test
OLD_PATH=
NEW_PATH="/${ALM_NEW_REL_PATH}"
REPLACE_FROM="DocumentRoot /opt/alminium/public"
REPLACE_TO="DocumentRoot /var/www/html\nRailsBaseURI ${NEW_PATH}"
ln -s /opt/alminium/public /var/www/html/${ALM_NEW_REL_PATH}
elif [ "${ALM_NEW_REL_PATH}" = "" ]
then
# case that rerative to non-rerative,
# ex.: http://localhost/alminium/projects/test
# ==> http://localhost/projects/test
OLD_PATH="/${ALM_OLD_REL_PATH}"
NEW_PATH=
REPLACE_FROM="DocumentRoot /var/www/html\nRailsBaseURI ${OLD_PATH}"
REPLACE_TO="DocumentRoot /opt/alminium/public"
rm /var/www/html/${ALM_OLD_REL_PATH}
else
# case that rerative to different rerative,
# ex.: http://localhost/alminium/projects/test
# ==> http://localhost/redmine/projects/test
OLD_PATH="/${ALM_OLD_REL_PATH}"
NEW_PATH="/${ALM_NEW_REL_PATH}"
REPLACE_FROM="RailsBaseURI ${OLD_PATH}"
REPLACE_TO="RailsBaseURI ${NEW_PATH}"
mv /var/www/html/${ALM_OLD_REL_PATH} /var/www/html/${ALM_NEW_REL_PATH}
fi
# modify apache configuration
cd /etc/opt/alminium
for FILE in $(ls redmine*.conf vcs.conf)
do
sed -i.old \
-e "s|${REPLACE_FROM}|${REPLACE_TO}|" \
-e "s|Location ${OLD_PATH}/|Location ${NEW_PATH}/|" \
-e "s|ScriptAlias ${OLD_PATH}/git|ScriptAlias ${NEW_PATH}/git|" \
-e "s|WSGIScriptAlias ${OLD_PATH}/git|WSGIScriptAlias ${NEW_PATH}/git|" \
${FILE}
done
# modify hook command
sed -i "s|localhost${OLD_PATH}|localhost${NEW_PATH}|g" \
/opt/alminium/bin/alm-sync-scm
# modify current relative path
echo ${ALM_NEW_REL_PATH} > /etc/opt/alminium/relative_path
fi
echo "rerative settings are ready."
echo "rerative path is ${ALM_NEW_REL_PATH} (old name is ${ALM_OLD_REL_PATH})"
#
# email
#
if [ "${SMTP_ENABLED}" = "true" ]
then
cd /opt/alminium/config/
echo "production:" > configuration.yml
echo " email_delivery:" >> configuration.yml
echo " delivery_method: :smtp" >> configuration.yml
echo " smtp_settings:" >> configuration.yml
echo " enable_starttls_auto: ${SMTP_ENALBLE_STARTTLS_AUTO}" >> configuration.yml
echo " address: ${SMTP_ADDRESS}" >> configuration.yml
echo " port: ${SMTP_PORT}" >> configuration.yml
echo " domain: ${SMTP_DOMAIN}" >> configuration.yml
echo " authentication: ${SMTP_AUTHENTICATION}" >> configuration.yml
echo " user_name: ${SMTP_USER_NAME}" >> configuration.yml
echo " password: ${SMTP_PASS}" >> configuration.yml
chown www-data:www-data configuration.yml
elif [ -f /opt/alminium/config/configuration.yml ]
then # remove old settings
rm -f /opt/alminium/config/configuration.yml
fi
#
# config backup
#
if [ "${ALM_ENABLE_AUTO_BACKUP}" = "y" ]; then
/opt/alminium/config-backup
else # no auto-backp
rm -f /etc/cron.d/alminium-backup-cron
fi
#
# config ssl
#
if [ "`grep "#SSL#" /etc/opt/alminium/alminium.conf`" = "" ]; then
ALM_ENABLE_SSL_OLD=y
else
ALM_ENABLE_SSL_OLD=N
fi
if [ "${ALM_ENABLE_SSL_OLD}" != "${ALM_ENABLE_SSL}" ]; then
# cp -p /etc/opt/alminium/alminium.conf /etc/opt/alminium/alminium.conf.old
# cp -p /etc/opt/alminium/redmine.conf /etc/opt/alminium/redmine.conf.old
if [ "${ALM_ENABLE_SSL_OLD}" = "N" -a "${ALM_ENABLE_SSL}" = "y" ]; then
sed -i.old "s|#SSL# *||" /etc/opt/alminium/alminium.conf
sed -i.old "s|#SSL# *||" /etc/opt/alminium/redmine.conf
sed -i.old "s|#SSL# *||" /etc/opt/alminium/jenkins.conf
a2enmod ssl
elif [ "${ALM_ENABLE_SSL_OLD}" = "y" -a "${ALM_ENABLE_SSL}" = "N" ]; then
sed -i.old "s|Include /etc/opt/alminium/redmine-ssl.conf|#SSL# Include /etc/opt/alminium/redmine-ssl.conf|" /etc/opt/alminium/alminium.conf
sed -i.old "s|Rewrite|#SSL# Rewrite|" /etc/opt/alminium/redmine.conf
sed -i.old \
-e "s|Header edit Location|#SSL# Header edit Location|" \
-e "s|RequestHeader set X_FORWARDED_PROTO|#SSL# RequestHeader set X_FORWARDED_PROTO|" \
/etc/opt/alminium/jenkins.conf
a2dismod ssl
fi
fi
# hostname
if [ "${ALM_PORT}" = "" -o "${ALM_PORT}" = "80" -o "${ALM_PORT}" = "443" ]; then
HOST_NAME="${ALM_HOSTNAME}${ALM_RELATIVE_URL_ROOT}"
else
HOST_NAME="${ALM_HOSTNAME}:${ALM_PORT}${ALM_RELATIVE_URL_ROOT}"
fi
db_update_setting host_name ${HOST_NAME}
# protocol
if [ "${ALM_ENABLE_SSL}" = "y" ]; then
db_update_setting protocol https
else
db_update_setting protocol http
fi
#
# Jenkins
#
if [ "${JENKINS_ENABLED}" = "true" ]; then
sed -i -e "/ProxyPass/d" \
-e "/BrowserMatch/a \ ProxyPassReverse ${JENKINS_URL}" \
-e "/BrowserMatch/a \ ProxyPass ${JENKINS_URL}" \
/etc/opt/alminium/jenkins.conf
sed -i -e "/jenkins\.conf/d" \
-e "/maven\.conf$/a Include \/etc\/opt\/alminium\/jenkins.conf" \
/etc/opt/alminium/alminium.conf
else
sed -i "/jenkins\.conf/d" /etc/opt/alminium/alminium.conf
fi
# go to HOMEDIR
cd ${ALM_HOME}
service apache2 restart