forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.10.0-190430.sh
More file actions
328 lines (287 loc) · 11.7 KB
/
Copy path0.10.0-190430.sh
File metadata and controls
328 lines (287 loc) · 11.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
#!/bin/bash
# define vars
HESTIA="/usr/local/hestia"
HESTIA_BACKUP="/root/hst_upgrade/$(date +%d%m%Y%H%M)"
hestiacp="$HESTIA/install/deb"
# Add webmail alias variable to system configuration if non-existent
webmail_alias_check=$(cat $HESTIA/conf/hestia.conf | grep WEBMAIL_ALIAS)
if [ -z "$WEBMAIL_ALIAS_CHECK" ]; then
echo "(*) Adding global webmail alias to system configuration..."
sed -i "/WEBMAIL_ALIAS/d" $HESTIA/conf/hestia.conf
echo "WEBMAIL_ALIAS='webmail'" >> $HESTIA/conf/hestia.conf
fi
# Add release branch system configuration if non-existent
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..."
sed -i "/RELEASE_BRANCH/d" $HESTIA/conf/hestia.conf
echo "RELEASE_BRANCH='develop'" >> $HESTIA/conf/hestia.conf
fi
# load hestia.conf
source $HESTIA/conf/hestia.conf
# load hestia main functions
source /usr/local/hestia/func/main.sh
# Initialize backup directory
mkdir -p $HESTIA_BACKUP/conf/
mkdir -p $HESTIA_BACKUP/packages/
mkdir -p $HESTIA_BACKUP/templates/
# Detect OS
case $(head -n1 /etc/issue | cut -f 1 -d ' ') in
Debian) os="debian" ;;
Ubuntu) os="ubuntu" ;;
esac
# Detect release for Debian
if [ "$os" = "debian" ]; then
release=$(cat /etc/debian_version|grep -o [0-9]|head -n1)
VERSION='debian'
elif [ "$os" = "ubuntu" ]; then
release="$(lsb_release -s -r)"
VERSION='ubuntu'
fi
# Clear the screen from apt output to prepare for upgrade installer experience
clear
echo
echo ' _ _ _ _ ____ ____ '
echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) |'
echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
echo
echo -e "\n\n"
echo " Hestia Control Panel Upgrade Script"
echo "==================================================="
echo ""
echo "Existing files will be backed up to the following location:"
echo "$HESTIA_BACKUP/"
echo ""
echo "This process may take a few moments, please wait..."
echo ""
# Set new version
sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
# Set new branch variable
echo "VERSION='0.10.0'" >> $HESTIA/conf/hestia.conf
# Update Apache and Nginx configuration to support new file structure
if [ -f /etc/apache2/apache.conf ]; then
echo "(*) Updating Apache configuration..."
mv /etc/apache2/apache.conf $HESTIA_BACKUP/conf/
cp -f $HESTIA/install/deb/apache2/apache.conf /etc/apache2/apache.conf
fi
if [ -f /etc/nginx/nginx.conf ]; then
echo "(*) Updating Nginx configuration..."
mv /etc/nginx/nginx.conf $HESTIA_BACKUP/conf/
cp -f $HESTIA/install/deb/nginx/nginx.conf /etc/nginx/nginx.conf
fi
# Generating dhparam
if [ ! -e /etc/ssl/dhparam.pem ]; then
echo "(*) Enabling HTTPS Strict Transport Security (HSTS) support..."
mv /etc/nginx/nginx.conf $HESTIA_BACKUP/conf/
cp -f $hestiacp/nginx/nginx.conf /etc/nginx/
# Copy dhparam
cp -f $hestiacp/ssl/dhparam.pem /etc/ssl/
# Update DNS servers in nginx.conf
dns_resolver=$(cat /etc/resolv.conf | grep -i '^nameserver' | cut -d ' ' -f2 | tr '\r\n' ' ' | xargs)
sed -i "s/1.0.0.1 1.1.1.1/$dns_resolver/g" /etc/nginx/nginx.conf
# Restart Nginx service
service nginx restart >/dev/null 2>&1
fi
# Update default page templates
echo "(*) Replacing default templates and packages..."
# Back up default package and install latest version
if [ -d $HESTIA/data/packages/ ]; then
cp -f $HESTIA/data/packages/default.pkg $HESTIA_BACKUP/packages/
fi
# Back up old template files and install the latest versions
if [ -d $HESTIA/data/templates/ ]; then
cp -rf $HESTIA/data/templates $HESTIA_BACKUP/templates/
$HESTIA/bin/v-update-web-templates
$HESTIA/bin/v-update-dns-templates
$HESTIA/bin/v-update-mail-templates
fi
# Remove old Office 365 template as there is a newer version with an updated name
if [ -f $HESTIA/data/templates/dns/o365.tpl ]; then
rm -f $HESTIA/data/templates/dns/o365.tpl
fi
# Back up and remove default index.html if it exists
if [ -f /var/www/html/index.html ]; then
mv /var/www/html/index.html $HESTIA_BACKUP/templates/
fi
# Configure default success page and set permissions on CSS, JavaScript, and Font dependencies for unassigned hosts
if [ ! -d /var/www/html ]; then
mkdir -p /var/www/html/
fi
if [ ! -d /var/www/document_errors/ ]; then
mkdir -p /var/www/document_errors/
fi
cp -rf $HESTIA/install/deb/templates/web/unassigned/* /var/www/html/
cp -rf $HESTIA/install/deb/templates/web/skel/document_errors/* /var/www/document_errors/
chmod 644 /var/www/html/*
chmod 751 /var/www/html/css
chmod 751 /var/www/html/js
chmod 751 /var/www/html/webfonts
chmod 644 /var/www/document_errors/*
chmod 751 /var/www/document_errors/css
chmod 751 /var/www/document_errors/js
chmod 751 /var/www/document_errors/webfonts
# Correct permissions on CSS, JavaScript, and Font dependencies for default templates
chmod 751 $HESTIA/data/templates/web/skel/document_errors/css
chmod 751 $HESTIA/data/templates/web/skel/document_errors/js
chmod 751 $HESTIA/data/templates/web/skel/document_errors/webfonts
chmod 751 $HESTIA/data/templates/web/skel/public_*html/css
chmod 751 $HESTIA/data/templates/web/skel/public_*html/js
chmod 751 $HESTIA/data/templates/web/skel/public_*html/webfonts
chmod 751 $HESTIA/data/templates/web/suspend/css
chmod 751 $HESTIA/data/templates/web/suspend/js
chmod 751 $HESTIA/data/templates/web/suspend/webfonts
chmod 751 $HESTIA/data/templates/web/unassigned/css
chmod 751 $HESTIA/data/templates/web/unassigned/js
chmod 751 $HESTIA/data/templates/web/unassigned/webfonts
# Correct other permissions
if [ -d "/var/cache/bind" ]; then
chown bind:bind /var/cache/bind
fi
if [ -d "/etc/roundcube" ]; then
chmod 640 /etc/roundcube/debian-db*
chown root:www-data /etc/roundcube/debian-db*
fi
# Add unassigned hosts configuration to Nginx and Apache
if [ "$WEB_SYSTEM" = "apache2" ]; then
echo "(*) Adding unassigned hosts configuration to Apache..."
for ip in /usr/local/hestia/data/ips/*; do
ipaddr=${ip##*/}
rm -f /etc/apache2/conf.d/$ip.conf
cp -f $HESTIA/install/deb/apache2/unassigned.conf /etc/apache2/conf.d/$ipaddr.conf
sed -i 's/directIP/'$ipaddr'/g' /etc/apache2/conf.d/$ipaddr.conf
done
fi
if [ "$PROXY_SYSTEM" = "nginx" ]; then
echo "(*) Adding unassigned hosts configuration to Nginx..."
for ip in /usr/local/hestia/data/ips/*; do
ipaddr=${ip##*/}
rm -f /etc/nginx/conf.d/$ip.conf
cp -f $HESTIA/install/deb/nginx/unassigned.inc /etc/nginx/conf.d/$ipaddr.conf
sed -i 's/directIP/'$ipaddr'/g' /etc/nginx/conf.d/$ipaddr.conf
done
fi
# Fix empty pool error message for MultiPHP
php_versions=$(ls /etc/php/*/fpm -d 2>/dev/null |wc -l)
if [ "$php_versions" -gt 1 ]; then
for v in $(ls /etc/php/); do
if [ ! -d "/etc/php/$v/fpm/pool.d/" ]; then
continue
fi
echo "(*) Updating Multi-PHP configuration..."
cp -f $hestiacp/php-fpm/dummy.conf /etc/php/$v/fpm/pool.d/
v1=$(echo "$v" | sed -e 's/[.]//')
sed -i "s/9999/99$v1/g" /etc/php/$v/fpm/pool.d/dummy.conf
done
fi
# Set Purge to false in Roundcube configuration - https://goo.gl/3Nja3u
echo "(*) Updating Roundcube configuration..."
if [ -f /etc/roundcube/config.inc.php ]; then
sed -i "s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/config.inc.php
fi
if [ -f /etc/roundcube/defaults.inc.php ]; then
sed -i "s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/defaults.inc.php
fi
if [ -f /etc/roundcube/main.inc.php ]; then
sed -i "s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/main.inc.php
fi
# Remove old OS-specific installation files if they exist to free up space
if [ -d $HESTIA/install/ubuntu ]; then
echo "(*) Removing old HestiaCP installation files for Ubuntu..."
rm -rf $HESTIA/install/ubuntu
fi
if [ -d $HESTIA/install/debian ]; then
echo "(*) Removing old HestiaCP installation files for Debian..."
rm -rf $HESTIA/install/debian
fi
# Fix Dovecot configuration
echo "(*) Updating Dovecot IMAP/POP server configuration..."
if [ -f /etc/dovecot/conf.d/15-mailboxes.conf ]; then
mv /etc/dovecot/conf.d/15-mailboxes.conf $HESTIA_BACKUP/conf/
fi
if [ -f /etc/dovecot/dovecot.conf ]; then
# Update Dovecot configuration and restart Dovecot service
mv /etc/dovecot/dovecot.conf $HESTIA_BACKUP/conf/
cp -f $HESTIA/install/deb/dovecot/dovecot.conf /etc/dovecot/dovecot.conf
systemctl restart dovecot
sleep 0.5
fi
# Fix Exim configuration
if [ -f /etc/exim4/exim4.conf.template ]; then
echo "(*) Updating Exim SMTP server configuration..."
mv /etc/exim4/exim4.conf.template $HESTIA_BACKUP/conf/
cp -f $HESTIA/install/deb/exim/exim4.conf.template /etc/exim4/exim4.conf.template
# Reconfigure spam filter and virus scanning
if [ ! -z "$ANTISPAM_SYSTEM" ]; then
sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
sed -i "s/#SPAM_SCORE/SPAM_SCORE/g" /etc/exim4/exim4.conf.template
fi
if [ ! -z "$ANTIVIRUS_SYSTEM" ]; then
sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
fi
fi
# Add IMAP system variable to configuration if Dovecot is installed
if [ -z "$IMAP_SYSTEM" ]; then
if [ -f /usr/bin/dovecot ]; then
echo "(*) Adding missing IMAP_SYSTEM variable to hestia.conf..."
echo "IMAP_SYSTEM = 'dovecot'" >> $HESTIA/conf/hestia.conf
fi
fi
# Remove Webalizer and set AWStats as default
echo "(*) Removing Webalizer and setting AWStats as default web statistics backend..."
apt purge webalizer -y > /dev/null 2>&1
sed -i "s/STATS_SYSTEM='webalizer,awstats'/STATS_SYSTEM='awstats'/g" $HESTIA/conf/hestia.conf
# Run sftp jail once
$HESTIA/bin/v-add-sys-sftp-jail
# Remove and migrate obsolete object keys
for user in `ls /usr/local/hestia/data/users/`; do
USER_DATA=$HESTIA/data/users/$user
# Web keys
for domain in $($BIN/v-list-web-domains $user plain |cut -f 1); do
obskey=$(get_object_value 'web' 'DOMAIN' "$domain" '$FORCESSL')
if [ ! -z "$obskey" ]; then
echo "(*) Fixing HTTP-to-HTTPS redirection for $domain"
update_object_value 'web' 'DOMAIN' "$domain" '$FORCESSL' ''
# copy value under new key name
add_object_key "web" 'DOMAIN' "$domain" 'SSL_FORCE' 'SSL_HOME'
update_object_value 'web' 'DOMAIN' "$domain" '$SSL_FORCE' "$obskey"
fi
unset FORCESSL
done
sed -i "s/\sFORCESSL=''//g" $USER_DATA/web.conf
done
# Rebuild user
for user in `ls /usr/local/hestia/data/users/`; do
echo "(*) Rebuilding domains and account for user: $user..."
v-rebuild-web-domains $user >/dev/null 2>&1
sleep 1
v-rebuild-dns-domains $user >/dev/null 2>&1
sleep 1
v-rebuild-mail-domains $user >/dev/null 2>&1
sleep 1
done
# Adding upgrade notification
$BIN/v-add-user-notification admin 'Upgrade complete' 'Your server has been updated to v0.10.0.<br>Please report any bugs on GitHub at<br>https://github.com/hestiacp/hestiacp/Issues<br><br>Have a great day!'
# Restart server services
echo "(*) Restarting services..."
sleep 5
$BIN/v-restart-mail $restart
$BIN/v-restart-service $IMAP_SYSTEM $restart
$BIN/v-restart-web $restart
$BIN/v-restart-proxy $restart
$BIN/v-restart-dns $restart
echo ""
echo " Upgrade complete! Please report any bugs or issues to"
echo " https://github.com/hestiacp/hestiacp/issues"
echo ""
echo " We hope that you enjoy this release of Hestia Control Panel,"
echo " enjoy your day!"
echo ""
echo " Sincerely,"
echo " The Hestia Control Panel development team"
echo ""
echo " www.hestiacp.com"
echo " Made with love & pride from the open-source community around the world."
echo ""
echo ""