-
Notifications
You must be signed in to change notification settings - Fork 16
/
hermes_migrate_1804_2004.sh
171 lines (120 loc) · 6.34 KB
/
hermes_migrate_1804_2004.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
#!/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 Tomcat Version
TOMCATVERSION="tomcat9"
TOMCATUSER="tomcat"
THEVERSION="20.04"
HERMES_SQL_USERNAME=`cat /opt/hermes/creds/hermes_username`
HERMES_SQL_PASSWORD=`cat /opt/hermes/creds/hermes_password`
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
source "$(pwd)/spinner.sh"
# test success
start_spinner 'sleeping for 2 secs...'
sleep 2
stop_spinner $?
PS3='This script will attempt to install various packages and migrate various settings for a Hermes SEG installation that was successfully upgraded from Ubuntu 18.04 to Ubuntu 20.04 using the do-release-upgrade command. 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 package installation and settings migration${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
start_spinner 'Installing Apache Tomcat...'
sleep 1
#Install Tomcat
apt-get install $TOMCATVERSION -y >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] Configuring Apache Tomcat for Ciphermail" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log
start_spinner 'Configuring Apache Tomcat for Ciphermail...'
sleep 1
#Configure Apache Tomcat for ciphermail
cp /etc/default/$TOMCATVERSION /etc/default/$TOMCATVERSION.ORIGINAL >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
echo "JAVA_OPTS=\"\$JAVA_OPTS -Ddjigzo-web.home=/usr/share/djigzo-web -Ddjigzo.home=/usr/share/djigzo\"" | sudo tee -a /etc/default/$TOMCATVERSION >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
echo "JAVA_OPTS=\"\$JAVA_OPTS -Djava.awt.headless=true -Xmx256M\"" | sudo tee -a /etc/default/$TOMCATVERSION >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
echo "<Context docBase=\"/usr/share/djigzo-web/djigzo.war\" />" | sudo tee /etc/$TOMCATVERSION/Catalina/localhost/ciphermail.xml >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
echo "<Context docBase=\"/usr/share/djigzo-web/djigzo-portal.war\" />" | sudo tee /etc/$TOMCATVERSION/Catalina/localhost/web.xml >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
cp /etc/$TOMCATVERSION/server.xml /etc/$TOMCATVERSION/server.ORIGINAL >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
cp /usr/share/djigzo-web/conf/tomcat/server.xml /etc/$TOMCATVERSION/ >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
sed -i 's/unpackWARs="false"/unpackWARs="true"/' /etc/$TOMCATVERSION/server.xml >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
chown $TOMCATUSER:djigzo /usr/share/djigzo-web/ssl/sslCertificate.p12 >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
systemctl restart $TOMCATVERSION >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
start_spinner 'Cleaning Up Old Apache Tomcat Files...'
sleep 1
#Delete Tomcat8
rm -rf /etc/tomcat8 >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1 && \
rm -rf /etc/default/tomcat8.ORIGINAL >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
start_spinner 'Installing Netplan...'
sleep 1
##TRY NETPLAN INSTALL IN CASE IT'S MISSING FROM UBUNTU 18.04 TO UBUNTU 20.04 UPGRADE
apt-get install netplan.io -y >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
start_spinner 'Installing Snap (If Necessary. This may fail if already installed)...'
sleep 1
##TRY SNAP INSTALL IN CASE IT'S MISSING FROM UBUNTU 18.04 TO UBUNTU 20.04 UPGRADE
apt-get install snapd -y >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
stop_spinner $?
start_spinner 'Outputting Certbot System Timers (Ensure snap.certbot.renew.service and snap.certbot.renew.timer are present)...'
sleep 1
ls -l /etc/systemd/system/ | grep certbot | boxes -d stone -p a2v1
stop_spinner $?
start_spinner 'Outputting Certbot Renew Timer (Ensure loaded active waiting appears below)...'
sleep 1
systemctl list-units | grep certbot.renew | boxes -d stone -p a2v1
stop_spinner $?
start_spinner 'Updating Hermes SEG Version...'
sleep 1
#UPDATE VERSION
echo "[`date +%m/%d/%Y-%H:%M`] Updating Hermes SEG Version" >> $SCRIPTPATH/migrate_log-$TIMESTAMP.log 2>&1
mysql -h localhost -u $HERMES_SQL_USERNAME -p$HERMES_SQL_PASSWORD -e "use hermes; update system_settings set value = '$THEVERSION' where parameter = 'version_no'"
stop_spinner $?
echo "[`date +%m/%d/%Y-%H:%M`] ==== FINISHED INSTALLATION ==== Ensure no errors were logged during installation" >> $SCRIPTPATH/install_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"