forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.sh
More file actions
407 lines (357 loc) · 15.7 KB
/
upgrade.sh
File metadata and controls
407 lines (357 loc) · 15.7 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#!/bin/bash
# Hestia Control Panel - Upgrade Control Script
#####################################################################
####### Functions & Initialization #######
#####################################################################
upgrade_welcome_message() {
echo
echo ' _ _ _ _ ____ ____ '
echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
echo " "
echo " Hestia Control Panel Software Update "
echo " Version: $new_version "
echo "========================================================================"
echo
echo "[ ! ] IMPORTANT INFORMATION: "
echo
echo "Default configuration files and templates may be modified or replaced "
echo "during the upgrade process. You may restore these files from: "
echo ""
echo "Backup directory: $HESTIA_BACKUP/ "
echo
echo "This process may take a few minutes, please wait... "
echo
echo "========================================================================"
echo
}
upgrade_complete_message() {
# Add notification to panel
$HESTIA/bin/v-add-user-notification admin 'Upgrade complete' 'Your server has been updated to Hestia Control Panel <b>v'$new_version'</b>.<br><br>Please tell us about any bugs or issues by opening an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a> or e-mail <a href="mailto:info@hestiacp.com?Subject="['$new_version'] Bug Report: ">info@hestiacp.com</a>.<br><br><b>Have a wonderful day!</b><br><br><i class="fas fa-heart status-icon red"></i> The Hestia Control Panel development team'
# Echo message to console output
echo
echo "========================================================================"
echo
echo "Upgrade complete! If you encounter any issues or find a bug, "
echo "please take a moment to report it to us on GitHub at the URL below: "
echo "https://github.com/hestiacp/hestiacp/issues "
echo
echo "We hope that you enjoy using this version of Hestia Control Panel, "
echo "have a wonderful day! "
echo
echo "Sincerely, "
echo "The Hestia Control Panel development team "
echo
echo "Web: https://www.hestiacp.com/ "
echo "Forum: https://forum.hestiacp.com/ "
echo "GitHub: https://github.com/hestiacp/hestiacp/ "
echo "E-mail: info@hestiacp.com "
echo
echo "Made with love & pride by the open-source community around the world. "
echo
echo
}
upgrade_init_backup() {
# Ensure that backup directories are created
# Hestia Control Panel configuration files
mkdir -p $HESTIA_BACKUP/conf/hestia/
# Hosting Packages
mkdir -p $HESTIA_BACKUP/packages/
# Domain template files
mkdir -p $HESTIA_BACKUP/templates/
# System services (apache2, nginx, bind9, vsftpd, etc).
if [ ! -z "$WEB_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
fi
if [ ! -z "$IMAP_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
fi
if [ ! -z "$DNS_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
fi
if [ ! -z "$PROXY_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
fi
if [ ! -z "$DB_SYSTEM" ]; then
if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
mkdir -p $HESTIA_BACKUP/conf/mysql/
fi
if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
mkdir -p $HESTIA_BACKUP/conf/pgsql/
fi
fi
if [ ! -z "$FTP_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
fi
if [ ! -z "$FIREWALL_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
fi
if [ ! -z "$FIREWALL_EXTENSION" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
fi
if [ -e "/etc/ssh/sshd_config" ]; then
mkdir -p $HESTIA_BACKUP/conf/ssh/
fi
echo "[ * ] Backing up existing templates and configuration files..."
cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
# Hestia Control Panel configuration files
cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
# System service configuration files (apache2, nginx, bind9, vsftpd, etc).
if [ ! -z "$WEB_SYSTEM" ]; then
cp -f /etc/$WEB_SYSTEM/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
cp -f /etc/$WEB_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
fi
if [ ! -z "$PROXY_SYSTEM" ]; then
cp -f /etc/$PROXY_SYSTEM/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
cp -f /etc/$PROXY_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
cp -f /etc/$PROXY_SYSTEM/conf.d/*.inc $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
fi
if [ ! -z "$IMAP_SYSTEM" ]; then
cp -f /etc/$IMAP_SYSTEM/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
cp -f /etc/$IMAP_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
cp -f /etc/$MAIL_SYSTEM/*.conf $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
fi
if [ ! -z "$DNS_SYSTEM" ]; then
if [ "$DNS_SYSTEM" = "bind9" ]; then
cp -f /etc/bind/*.conf $HESTIA_BACKUP/conf/$DNS_SYSTEM/
fi
fi
if [ ! -z "$DB_SYSTEM" ]; then
if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/mysql/
cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/
fi
if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/pgsql/
cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/pgsql/
fi
fi
if [ ! -z "$FTP_SYSTEM" ]; then
if [ "$FTP_SYSTEM" = "vsftpd" ]; then
cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
fi
if [ "$FTP_SYSTEM" = "proftpd" ]; then
cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
fi
fi
if [ ! -z "$FIREWALL_EXTENSION" ]; then
cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
fi
if [ -e "/etc/ssh/sshd_config" ]; then
cp -f /etc/ssh/sshd_config $HESTIA_BACKUP/conf/ssh/sshd_config
fi
}
upgrade_refresh_config() {
source /usr/local/hestia/conf/hestia.conf
source /usr/local/hestia/func/main.sh
}
upgrade_start_routine() {
#####################################################################
####### Ensure that release branch variable exists #######
#####################################################################
release_branch_check=$(cat $HESTIA/conf/hestia.conf | grep RELEASE_BRANCH)
if [ -z "$release_branch_check" ]; then
echo "[ * ] Adding global release branch variable to system configuration..."
$BIN/v-change-sys-config-value 'RELEASE_BRANCH' 'release'
fi
#####################################################################
####### Start standard upgrade process #######
####### Place instructions for all post v1.0.1 builds below #######
#####################################################################
# Ensure that latest upgrade commands are processed if version is the same
if [ $VERSION = "$new_version" ]; then
echo "[ ! ] The latest version of Hestia Control Panel is already installed."
echo " Verifying configuration..."
echo ""
source $HESTIA/install/upgrade/versions/latest.sh
VERSION="$new_version"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
if [ $VERSION = "0.9.8-25" ] || [ $VERSION = "0.9.8-26" ] || [ $VERSION = "0.9.8-27" ] || [ $VERSION = "0.9.8-28" ] || [ $VERSION = "0.9.8-29" ] || [ $VERSION = "0.10.0" ] || [ $VERSION = "1.00.0-190618" ] || [ $VERSION = "1.00.0-190621" ] || [ $VERSION = "1.0.0" ]; then
source $HESTIA/install/upgrade/versions/previous/0.9.8-29.sh
source $HESTIA/install/upgrade/versions/previous/1.00.0-190618.sh
source $HESTIA/install/upgrade/versions/previous/1.0.1.sh
VERSION="1.0.1"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.0.2
if [ $VERSION = "1.0.1" ]; then
source $HESTIA/install/upgrade/versions/previous/1.0.2.sh
VERSION="1.0.2"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.0.3
if [ $VERSION = "1.0.2" ]; then
source $HESTIA/install/upgrade/versions/previous/1.0.3.sh
VERSION="1.0.3"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.0.4
if [ $VERSION = "1.0.3" ]; then
source $HESTIA/install/upgrade/versions/previous/1.0.4.sh
VERSION="1.0.4"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.0.5
if [ $VERSION = "1.0.4" ]; then
source $HESTIA/install/upgrade/versions/previous/1.0.5.sh
VERSION="1.0.5"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.0.6
if [ $VERSION = "1.0.5" ]; then
source $HESTIA/install/upgrade/versions/previous/1.0.6.sh
VERSION="1.0.6"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.1.0
if [ $VERSION = "1.0.6" ]; then
source $HESTIA/install/upgrade/versions/previous/1.1.0.sh
VERSION="1.1.0"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.1.1
if [ $VERSION = "1.1.0" ]; then
source $HESTIA/install/upgrade/versions/previous/1.1.1.sh
VERSION="1.1.1"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.2.0
if [ $VERSION = "1.1.1" ] || [ $VERSION = "1.1.2" ]; then
source $HESTIA/install/upgrade/versions/previous/1.2.0.sh
VERSION="1.2.1"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
# Upgrade to Version 1.2.1
if [ $VERSION = "1.2.0" ]; then
# Process steps which may not have correctly executed from v1.1.0.
echo
echo "[ ! ] Reprocessing steps from v1.1.0 due to a previous installer bug..."
echo
source $HESTIA/install/upgrade/versions/previous/1.1.0.sh
source $HESTIA/install/upgrade/versions/previous/1.2.0.sh
VERSION="1.2.1"
upgrade_refresh_config
fi
# Upgrade to Version 1.2.2
if [ $VERSION = "1.2.1" ]; then
source $HESTIA/install/upgrade/versions/latest.sh
VERSION="$new_version"
upgrade_refresh_config
fi
#####################################################################
####### End version-specific upgrade instruction sets #######
#####################################################################
}
upgrade_phpmyadmin() {
# Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
if [ "$DB_SYSTEM" = "mysql" ]; then
# Define version check function
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
if version_ge "${pma_release_file##*-}" "$pma_v"; then
echo "[ ! ] phpMyAdmin v${pma_release_file##*-} is already installed, skipping update..."
else
# Display upgrade information
echo "[ * ] Upgrading phpMyAdmin to version v$pma_v..."
[ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
# Download latest phpMyAdmin release
wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
# Unpack files
tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
# Delete file to prevent error
rm -fr /usr/share/phpmyadmin/doc/html
# Overwrite old files
cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
# Set config and log directory
sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
# Create temporary folder and change permissions
if [ ! -d /usr/share/phpmyadmin/tmp ]; then
mkdir /usr/share/phpmyadmin/tmp
chmod 777 /usr/share/phpmyadmin/tmp
fi
# Clean up source files
rm -fr phpMyAdmin-$pma_v-all-languages
rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
fi
fi
}
upgrade_get_version() {
# Retrieve new version number for Hestia Control Panel from .deb package
new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
}
upgrade_set_version() {
# Set new version number in hestia.conf
sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
echo "VERSION='$@'" >> $HESTIA/conf/hestia.conf
}
upgrade_rebuild_users() {
for user in $($HESTIA/bin/v-list-sys-users plain); do
echo "[ * ] Rebuilding domains and account for user: $user..."
if [ ! -z "$WEB_SYSTEM" ]; then
$BIN/v-rebuild-web-domains $user 'no' >/dev/null 2>&1
fi
if [ ! -z "$DNS_SYSTEM" ]; then
$BIN/v-rebuild-dns-domains $user 'no' >/dev/null 2>&1
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
$BIN/v-rebuild-mail-domains $user 'no' >/dev/null 2>&1
fi
$BIN/v-rebuild-user $user 'no' >/dev/null 2>&1
done
}
upgrade_restart_services() {
# Refresh user interface theme
if [ "$THEME" ]; then
if [ "$THEME" != "default" ]; then
echo "[ * ] Applying user interface updates..."
$BIN/v-change-sys-theme $THEME
fi
fi
echo "[ * ] Restarting services..."
sleep 5
if [ ! -z "$MAIL_SYSTEM" ]; then
$BIN/v-restart-mail $restart
fi
if [ ! -z "$WEB_SYSTEM" ]; then
$BIN/v-restart-web $restart
$BIN/v-restart-proxy $restart
fi
if [ ! -z "$DNS_SYSTEM" ]; then
$BIN/v-restart-dns $restart
fi
for v in `ls /etc/php/`; do
if [ -e /etc/php/$v/fpm ]; then
$BIN/v-restart-service php$v-fpm $restart
fi
done
if [ ! -z "$FTP_SYSTEM" ]; then
$BIN/v-restart-ftp $restart
fi
if [ ! -z "$FIREWALL_EXTENSION" ]; then
$BIN/v-restart-service $FIREWALL_EXTENSION yes
fi
# Restart SSH daemon and Hestia Control Panel service
$BIN/v-restart-service ssh $restart
$BIN/v-restart-service hestia $restart
}