-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhermes_upgrade_lucee.sh
305 lines (207 loc) · 9.37 KB
/
hermes_upgrade_lucee.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
303
304
305
#!/bin/bash
#Ensure Script is run as root and if not exit
if [ `id -u` -ne 0 ]; then
echo "This script must be executed as root, Exiting..."
exit 1
fi
#Ensure Ubuntu 20.04
string=`lsb_release -d`
if [[ $string == *"Ubuntu 18.04"* ]]; then
echo "You must be running Ubuntu 20.04 before running this script, Exiting..."
exit 1
fi
#Set the script path
SCRIPTPATH=$(pwd)
#Set migrate_log Date/Time Stamp
TIMESTAMP=`date +%m-%d-%Y-%H%M`
#Set Font Colors
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
echo "Installing Boxes Prerequisite if necessary"
#Install boxes
apt-get install boxes -y > /dev/null 2>&1
ERR=$?
if [ $ERR != 0 ]; then
THEERROR=$(($THEERROR+$ERR))
echo "${RED}Error $THEERROR, occurred Installing Boxes Prerequisite ${RESET}"
exit 1
else
echo "${GREEN}Completed Installing Boxes Prerequisite ${RESET}"
fi
echo "Installing Spinner Prerequisite if necessary"
#Install spinner
apt-get install spinner -y > /dev/null 2>&1
ERR=$?
if [ $ERR != 0 ]; then
THEERROR=$(($THEERROR+$ERR))
echo "${RED}Error $THEERROR, occurred Installing Spinner Prerequisite ${RESET}"
exit 1
else
echo "${GREEN}Completed Installing Spinner Prerequisite ${RESET}"
fi
echo "Downloading spinner.sh"
#Download spinner.sh
wget https://gitlab.deeztek.com/dedwards/hermes-seg-18.04/-/raw/master/spinner.sh > /dev/null 2>&1
ERR=$?
if [ $ERR != 0 ]; then
THEERROR=$(($THEERROR+$ERR))
echo "${RED}Error $THEERROR, occurred Downloading spinner.sh ${RESET}"
exit 1
else
echo "${GREEN}Completed Downloading spinner.sh ${RESET}"
fi
source "$(pwd)/spinner.sh"
# test success
start_spinner 'sleeping for 2 secs...'
sleep 2
stop_spinner $?
PS3='This script will attempt to either migrate your Hermes SEG from Lucee to Commandbox if applicable or upgrade Lucee in existing Commandbox installations. Ensure that you have a fresh and valid backup of your machine before proceeding. This script is offered with absolutely no warrranty or guarantee of any kind. We cannot be held liable for any damage that may occur to your system. Do you agree with the terms of this script?: '
options=("Yes - I agree" "No - I do not agree")
select opt in "${options[@]}"
do
case $opt in
"Yes - I agree")
echo "${GREEN}Starting Upgrade...${RESET}" | boxes -d stone -p a2v1
echo "During installation a ${RED}$SCRIPTPATH/migrate_log-$TIMESTAMP.log${RESET} log file will be created. It's highly recommended that you open a separate shell window and tail that file in order to view progress of the installation and/or any errors that may occur."
echo "[`date +%m/%d/%Y-%H:%M`] Starting package installation and settings migration." >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
break
;;
"No - I do not agree")
echo "Exiting ... ";
exit
;;
*) echo "Invalid option $REPLY ";;
esac
done
# BAT / CMD goto function
function goto
{
label=$1
cmd=$(sed -n "/^:[[:blank:]][[:blank:]]*${label}/{:a;n;p;ba};" $0 |
grep -v ':$')
eval "$cmd"
exit
}
# Just for the heck of it: how to create a variable where to jump to:
start=${1:-"start"}
goto "start"
: start
#If Lucee is enabled goto install
STR=`systemctl is-enabled lucee_ctl`
SUB='enabled'
if [[ "$STR" == *"$SUB"* ]]; then
echo "Commandbox not found. Proceeding with installation..."
goto "migrate"
else
goto "checkcommandbox"
fi
: checkcommandbox
#If Commandbox has Lucee 5.2.9 goto upgrade
File="/var/www/html/server.json"
if grep -q [email protected] "$File"; then
echo "Commandbox with Lucee 5.3.5 Found. Proceeding with upgrade regardless...."
goto "upgrade"
else
echo "Commandbox with Lucee 5.2.9 Found. Proceeding with upgrade..."
goto "upgrade"
fi
: migrate
echo "[`date +%m/%d/%Y-%H:%M`] Cloning Repo...." >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Cloning Repo...'
sleep 1
#Clone Repo
git clone http://gitlab.deeztek.com/dedwards/hermes-seg-18.04.git $SCRIPTPATH/hermes-seg-18.04 >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Disabling Lucee Service" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Disabling Lucee Service...'
sleep 1
#Disable Lucee Service
systemctl disable lucee_ctl >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Uninstalling Lucee" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Uninstalling Lucee...'
sleep 1
#Uninstall Lucee
/opt/lucee/uninstall --mode unattended >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Installing Commandbox" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Installing Commandbox...'
sleep 1
#Install Commandbox
curl -fsSl https://downloads.ortussolutions.com/debs/gpg | sudo apt-key add - >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
echo "deb https://downloads.ortussolutions.com/debs/noarch /" | sudo tee -a /etc/apt/sources.list.d/commandbox.list >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
apt-get update >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
apt-get install apt-transport-https commandbox -y >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Configuring Commandbox Server Parameters" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Configuring Commandbox Server Parameters...'
sleep 1
#Configure Commandbox
cp $SCRIPTPATH/hermes-seg-18.04/download/commandbox/server_5.3.5.json /var/www/html/server.json >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Configuring and Starting Hermes SEG Service" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Configuring and Starting Hermes SEG Service...'
sleep 1
#Configure Hermes SEG Service
cp $SCRIPTPATH/hermes-seg-18.04/download/commandbox/hermesseg.service /etc/systemd/system/hermesseg.service >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
systemctl enable --now hermesseg.service >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
systemctl restart hermesseg.service >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Generating Random Commandbox Lucee Server and Web Administrator Password" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Generating Random Commandbox Lucee Server and Web Administrator Password...'
sleep 1
LUCEE_ADMIN_PASSWORD=`openssl rand -hex 20`
#Export the variable
export LUCEE_ADMIN_PASSWORD
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Random Password is: $LUCEE_ADMIN_PASSWORD" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
echo "Random Password is:${GREEN} $LUCEE_ADMIN_PASSWORD ${RESET}" | boxes -d stone -p a2v1
echo "[`date +%m/%d/%Y-%H:%M`] Configuring Commandbox Lucee Server and Web Administrator Password" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Configuring Commandbox Lucee Server and Web Administrator Password...'
sleep 1
#Configure Lucee Server and Web Administrator Password
cp $SCRIPTPATH/hermes-seg-18.04/download/commandbox/password.txt /opt/CommandBox/web-contexts/wwwroot-hermesseg/WEB-INF/lucee-server/context/password.txt >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
sed -i -e "s|LUCEE-PASSWORD|$LUCEE_ADMIN_PASSWORD|g" "/opt/CommandBox/web-contexts/wwwroot-hermesseg/WEB-INF/lucee-server/context/password.txt" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Copying NEW Compiled Files..." >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Copying NEW Compiled Files...'
sleep 1
#Copy new compiled files
cp -rf $SCRIPTPATH/hermes-seg-18.04/proprietary_535/* /var/www/html/admin 2>> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
stop_spinner $?
goto "done"
: upgrade
echo "[`date +%m/%d/%Y-%H:%M`] Cloning Repo...." >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Cloning Repo...'
sleep 1
#Clone Repo
git clone http://gitlab.deeztek.com/dedwards/hermes-seg-18.04.git $SCRIPTPATH/hermes-seg-18.04 >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Upgrading Lucee to 5.3.5 in Commandbox" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Upgrading Lucee to 5.3.5 in Commandbox...'
sleep 1
#Upgrade Lucee in commandbox
cp $SCRIPTPATH/hermes-seg-18.04/download/commandbox/server_5.3.5.json /var/www/html/server.json >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
start_spinner 'Removing Lucee Artifacts from Commandbox...'
sleep 1
#Remove artifacts
yes | /usr/local/bin/box artifacts remove lucee >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
start_spinner 'Deleting Commandbox Home Directory...'
sleep 1
#Delete commandbox home directory
rm -rf /opt/CommandBox/ >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Copying NEW Compiled Files..." >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Copying NEW Compiled Files...'
sleep 1
#Copy new compiled files
cp -rf $SCRIPTPATH/hermes-seg-18.04/proprietary_535/* /var/www/html/admin 2>> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
stop_spinner $?
goto "done"
: done
echo "[`date +%m/%d/%Y-%H:%M`] ==== FINISHED INSTALLATION ==== Ensure no errors were logged during installation" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
echo "${GREEN}FINISHED INSTALLATION. PLEASE REBOOT YOUR MACHINE!!${RESET}" | boxes -d stone -p a2v1
echo "Take a look at the ${GREEN}$SCRIPTPATH/migrate_log-$TIMESTAMP.log${RESET} file for any errors"