-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathupgrade-os
178 lines (154 loc) · 6.96 KB
/
upgrade-os
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
#!/usr/bin/env bash
set -e
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
UBUNTU_VERSION=$(lsb_release -rs)
checkDpkgLock () {
while sudo fuser /var/lib/dpkg/lock /var/lib/apt/lists/lock /var/cache/apt/archives/lock >/dev/null 2>&1
do
echo 'Operating system is using dpkg/apt locks, waiting for their release...'
sleep 5
done
}
checkIfRebootNeeded () {
if [ -f /var/run/reboot-required ]
then
echo -e "\033[0;33mThe server will now reboot, resuming the update process directly afterwards.\033[0m"
echo -e "\033[0;33mDuring this time, paired machines will not be online.\033[0m"
echo
echo -e "\033[0;33mPlease wait 30 minutes before logging back into your server's terminal.\033[0m"
echo
echo -e "\033[0;33mAfter logging in, consult the update process and the required next step with the following command:\033[0m"
echo
echo -e "\033[0;33mcheck-upgrade-status\033[0m"
echo
sudo shutdown -r now
fi
}
checkIfCanContinue () {
checkIfRebootNeeded
checkDpkgLock
}
addPackageSources () {
if [[ "$UBUNTU_VERSION" == "16.04" ]]; then
if ! mkdir /var/lock/xenial-upgrade; then
echo "Xenial package sources already added." >&2
else
echo "deb http://archive.ubuntu.com/ubuntu/ xenial main universe multiverse" >> /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu/ xenial-security main universe multiverse" >> /etc/apt/sources.list
fi
elif [[ "$UBUNTU_VERSION" == "18.04" ]]; then
if ! mkdir /var/lock/bionic-upgrade; then
echo "Bionic package sources already added." >&2
else
echo "deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted" >> /etc/apt/sources.list
fi
fi
}
cat <<'FIG'
_
| | __ _ _ __ ___ __ _ ___ ___ _ _ ___ ___ _ ____ _____ _ __
| |/ _` | '_ ` _ \ / _` / __/ __| | | |_____/ __|/ _ \ '__\ \ / / _ \ '__|
| | (_| | | | | | | (_| \__ \__ \ |_| |_____\__ \ __/ | \ V / __/ |
|_|\__,_|_| |_| |_|\__,_|___/___/\__,_| |___/\___|_| \_/ \___|_|
FIG
echo -e "\nStarting \033[1mlamassu-server\033[0m OS update. This will take a while...\n"
if [ "$(whoami)" != "root" ]; then
echo -e "This script has to be run as \033[1mroot\033[0m user"
exit 3
fi
# Use a lock file so failed scripts cannot be imediately retried
# If not the backup created on this script would be replaced
if ! mkdir /var/lock/lamassu-update; then
echo "Script is locked because of a failure." >&2
exit 1
fi
if [ -f /usr/bin/check-upgrade-status ]; then
rm -r /usr/bin/check-upgrade-status
fi
echo "tail -n 10 ~/upgrade.log" > /usr/bin/check-upgrade-status
sudo chmod +x /usr/bin/check-upgrade-status
addPackageSources
supervisorctl stop lamassu-server lamassu-admin-server
if [[ "$UBUNTU_VERSION" == "16.04" ]]; then
echo "Detected Ubuntu version: 16.04. Updating to Ubuntu version: 18.04..."
echo
echo -e "\033[0;33mNOTE: Some of the system's dependencies might require more reboots than expected during this process.\033[0m"
echo
command="/usr/bin/curl -sS https://raw.githubusercontent.com/lamassu/lamassu-install/electric-enlil/upgrade-os | bash >> ~/upgrade.log"
job="@reboot root sleep 5 | $command"
echo "$job" > /etc/cron.d/lamassu-upgrade
echo -e "\033[0;33mupdating to node 14\033[0m"
npm install -g n
sudo n 14
sudo n which 14
checkDpkgLock
echo -e "\033[0;33mupdating to ubuntu 18.04\033[0m"
sudo apt-get update -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
checkIfCanContinue
sudo DEBIAN_FRONTEND=noninteractive apt-get --with-new-pkgs upgrade -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
checkIfCanContinue
sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
checkIfCanContinue
sudo do-release-upgrade -f DistUpgradeViewNonInteractive
echo
echo -e "\033[0;33mUbuntu successfully updated to version 18.04!\033[0m"
echo -e "\033[0;33mThe server will now reboot, resuming the update process directly afterwards.\033[0m"
echo -e "\033[0;33mDuring this time, paired machines will not be online.\033[0m"
echo
echo -e "Please wait 30 minutes before logging back into your server's terminal."
echo
echo -e "After logging in, consult the update process and the required next step with the following command:"
echo
echo -e "\033[0;33mcheck-upgrade-status\033[0m"
echo
rm -r /var/lock/lamassu-update
rm -r /var/lock/xenial-upgrade
sudo shutdown -r now
elif [[ "$UBUNTU_VERSION" == "18.04" ]]; then
echo "Detected Ubuntu version: 18.04. Updating to Ubuntu version: 20.04..."
echo
echo -e "\033[0;33mNOTE: Some of the system's dependencies might require more reboots than expected during this process.\033[0m"
echo
command="/usr/bin/curl -sS https://raw.githubusercontent.com/lamassu/lamassu-install/electric-enlil/upgrade-os | bash >> ~/upgrade.log"
job="@reboot root sleep 5 | $command"
echo "$job" > /etc/cron.d/lamassu-upgrade
checkDpkgLock
echo -e "\033[0;33mupdating to ubuntu 20.04\033[0m"
sudo apt-get update -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
checkIfCanContinue
sudo DEBIAN_FRONTEND=noninteractive apt-get --with-new-pkgs upgrade -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
checkIfCanContinue
sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
checkIfCanContinue
sudo do-release-upgrade -f DistUpgradeViewNonInteractive
echo
echo -e "\033[0;33mUbuntu successfully updated to version 20.04!\033[0m"
echo -e "\033[0;33mThe server will now reboot, resuming the update process directly afterwards.\033[0m"
echo -e "\033[0;33mDuring this time, paired machines will not be online.\033[0m"
echo
echo -e "\033[0;33mPlease wait 30 minutes before logging back into your server's terminal.\033[0m"
echo
echo -e "\033[0;33mAfter logging in, consult the update process and the required next step with the following command:\033[0m"
echo
echo -e "\033[0;33mcheck-upgrade-status\033[0m"
echo
rm -r /var/lock/lamassu-update
rm -r /var/lock/bionic-upgrade
sudo shutdown -r now
elif [[ "$UBUNTU_VERSION" == "20.04" ]]; then
echo "Detected Ubuntu version: 20.04. Your operating system is up-to-date."
echo
echo -e "\033[0;33mTo complete the upgrade, you must now update lamassu-server to the latest release.\033[0m"
echo -e "\033[0;33mYour paired machines will be offline until doing so.\033[0m"
echo
echo -e "\033[0;33mTo finalise the upgrade, please run the following command:\033[0m"
echo
echo -e "\033[1mcurl -sS https://raw.githubusercontent.com/lamassu/lamassu-install/grand-gilgamesh/upgrade-ls | bash\033[0m"
echo
if [ -f /etc/cron.d/lamassu-upgrade ]; then
rm -r /etc/cron.d/lamassu-upgrade
fi
else
echo -e "\033[0;31mIncompatible Ubuntu version detected ($UBUNTU_VERSION). Make sure that Ubuntu is on one of the following versions: 16.04, 18.04, 20.04.\033[0m"
fi
rm -r /var/lock/lamassu-update