Skip to content

Commit 3e08b3b

Browse files
author
Kristan Kenney
committed
Refactor upgrade scripts and routine for previous releases
1 parent 89ddfba commit 3e08b3b

File tree

5 files changed

+85
-145
lines changed

5 files changed

+85
-145
lines changed

install/upgrade/restart.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ fi
2929
if [ ! -z $DNS_SYSTEM ]; then
3030
$BIN/v-restart-dns $restart
3131
fi
32+
for v in `ls /etc/php/`; do
33+
if [ -e /etc/php/$v/fpm ]; then
34+
sleep 5
35+
$BIN/v-restart-service php$v-fpm $restart
36+
fi
37+
done
3238

3339
# Restart SSH daemon and Hestia Control Panel service
3440
$BIN/v-restart-service ssh $restart

install/upgrade/versions/0.9.8-28.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
2-
HESTIA="/usr/local/hestia"
3-
HESTIA_BACKUP="/root/hst_upgrade/$(date +%d%m%Y%H%M)"
4-
spinner="/-\|"
52

6-
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
3+
# Hestia Control Panel upgrade script for target version 0.9.8-28
4+
5+
#######################################################################################
6+
####### Place additional commands below. #######
7+
#######################################################################################
8+
79

810
# Add amd64 to repositories to prevent notifications - https://goo.gl/hmsSV7
911
if ! grep -q 'arch=amd64' /etc/apt/sources.list.d/nginx.list; then

install/upgrade/versions/1.0.1.sh

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
#!/bin/bash
22

3-
# Define version check function
4-
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
3+
# Hestia Control Panel upgrade script for target version 1.0.1
54

6-
# Set new version number
7-
NEW_VERSION="1.0.1"
8-
9-
# Set phpMyAdmin version for upgrade
10-
pma_v='4.9.0.1'
11-
12-
# Set backup folder
13-
HESTIA_BACKUP="/root/hst_upgrade/$(date +%d%m%Y%H%M)"
14-
15-
# Set installation source folder
16-
hestiacp="$HESTIA/install/deb"
17-
18-
# Load hestia.conf
19-
source /usr/local/hestia/conf/hestia.conf
20-
21-
####### Place additional commands below. #######
5+
#######################################################################################
6+
####### Place additional commands below. #######
7+
#######################################################################################
228

239
# Ensure that users from previous releases are set to the correct stable release branch
2410
if [ $RELEASE_BRANCH = "master" ] || [ $RELEASE_BRANCH = "develop" ]; then
@@ -27,55 +13,18 @@ if [ $RELEASE_BRANCH = "master" ] || [ $RELEASE_BRANCH = "develop" ]; then
2713
echo "RELEASE_BRANCH='release'" >> $HESTIA/conf/hestia.conf
2814
fi
2915

30-
# Add amd64 to repositories to prevent notifications - https://goo.gl/hmsSV7
31-
if ! grep -q 'arch=amd64' /etc/apt/sources.list.d/nginx.list; then
32-
sed -i s/"deb "/"deb [arch=amd64] "/g /etc/apt/sources.list.d/nginx.list
3316
# Back up old template files and install the latest versions
3417
if [ -d $HESTIA/data/templates/ ]; then
35-
echo "(*) Updating and rebuild web templates..."
18+
echo "(*) Updating web templates to enable per-domain HSTS/OCSP SSL support..."
3619
cp -rf $HESTIA/data/templates $HESTIA_BACKUP/templates/
37-
$HESTIA/bin/v-update-web-templates
20+
$HESTIA/bin/v-update-web-templates >/dev/null 2>&1
3821
fi
3922

40-
# Update Apache and Nginx configuration to support new file structure
41-
echo "(*) Updating web server configuration..."
42-
if [ -f /etc/apache2/apache.conf ]; then
43-
mv /etc/apache2/apache.conf $HESTIA_BACKUP/conf/
44-
cp -f $HESTIA/install/deb/apache2/apache.conf /etc/apache2/apache.conf
45-
fi
46-
if [ -f /etc/nginx/nginx.conf ]; then
47-
mv /etc/nginx/nginx.conf $HESTIA_BACKUP/conf/
48-
cp -f $HESTIA/install/deb/nginx/nginx.conf /etc/nginx/nginx.conf
23+
# Remove global options from nginx.conf to prevent conflicts with other web packages
24+
# and remove OCSP SSL stapling from global configuration as it has moved to per-domain availability in this release.
25+
if [ -e /etc/nginx/nginx.conf ]; then
26+
sed -i "/add_header X-Frame-Options SAMEORIGIN;/d" /etc/nginx/nginx.conf
27+
sed -i "/add_header X-Content-Type-Options nosniff;/d" /etc/nginx/nginx.conf
28+
sed -i "/ssl_stapling on;/d" /etc/nginx/nginx.conf
29+
sed -i "/ssl_stapling_verify on;/d" /etc/nginx/nginx.conf
4930
fi
50-
51-
# Generate dhparam
52-
if [ ! -e /etc/ssl/dhparam.pem ]; then
53-
mv /etc/nginx/nginx.conf $HESTIA_BACKUP/conf/
54-
cp -f $hestiacp/nginx/nginx.conf /etc/nginx/
55-
56-
# Copy dhparam
57-
cp -f $hestiacp/ssl/dhparam.pem /etc/ssl/
58-
59-
# Update DNS servers in nginx.conf
60-
dns_resolver=$(cat /etc/resolv.conf | grep -i '^nameserver' | cut -d ' ' -f2 | tr '\r\n' ' ' | xargs)
61-
for ip in $dns_resolver; do
62-
if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
63-
resolver="$ip $resolver"
64-
fi
65-
done
66-
if [ ! -z "$resolver" ]; then
67-
sed -i "s/1.0.0.1 1.1.1.1/$resolver/g" /etc/nginx/nginx.conf
68-
fi
69-
70-
# Remove global options from nginx.conf to prevent conflicts with other web packages
71-
if [ -e /etc/nginx/nginx.conf ]; then
72-
sed -i "/add_header X-Frame-Options SAMEORIGIN;/d" /etc/nginx/nginx.conf
73-
sed -i "/add_header X-Content-Type-Options nosniff;/d" /etc/nginx/nginx.conf
74-
fi
75-
76-
# Restart Nginx service
77-
systemctl restart nginx >/dev/null 2>&1
78-
fi
79-
80-
81-

install/upgrade/versions/1.00.0-190618.sh

Lines changed: 45 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,60 @@
11
#!/bin/bash
22

3-
# Define version check function
4-
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
3+
# Hestia Control Panel upgrade script for target version 1.00.0-190618
54

6-
# Load hestia.conf
7-
source /usr/local/hestia/conf/hestia.conf
5+
#######################################################################################
6+
####### Place additional commands below. #######
7+
#######################################################################################
88

9-
####### Place additional commands below. #######
9+
# Add webmail alias variable to system configuration if non-existent
10+
WEBMAIL_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep WEBMAIL_ALIAS)
11+
if [ -z "$WEBMAIL_ALIAS_CHECK" ]; then
12+
echo "(*) Adding global webmail alias to system configuration..."
13+
sed -i "/WEBMAIL_ALIAS/d" $HESTIA/conf/hestia.conf
14+
echo "WEBMAIL_ALIAS='webmail'" >> $HESTIA/conf/hestia.conf
15+
fi
1016

11-
# Add amd64 to repositories to prevent notifications - https://goo.gl/hmsSV7
12-
if ! grep -q 'arch=amd64' /etc/apt/sources.list.d/nginx.list; then
13-
sed -i s/"deb "/"deb [arch=amd64] "/g /etc/apt/sources.list.d/nginx.list
17+
# Update Apache and Nginx configuration to support new file structure
18+
if [ -f /etc/apache2/apache.conf ]; then
19+
echo "(*) Updating Apache configuration..."
20+
mv /etc/apache2/apache.conf $HESTIA_BACKUP/conf/
21+
cp -f $HESTIA/install/deb/apache2/apache.conf /etc/apache2/apache.conf
1422
fi
15-
if ! grep -q 'arch=amd64' /etc/apt/sources.list.d/mariadb.list; then
16-
sed -i s/"deb "/"deb [arch=amd64] "/g /etc/apt/sources.list.d/mariadb.list
23+
if [ -f /etc/nginx/nginx.conf ]; then
24+
echo "(*) Updating NGINX configuration..."
25+
mv /etc/nginx/nginx.conf $HESTIA_BACKUP/conf/
26+
cp -f $HESTIA/install/deb/nginx/nginx.conf /etc/nginx/nginx.conf
1727
fi
1828

19-
# Add webmail alias variable to system configuration if non-existent
20-
imap_check=$(cat $HESTIA/conf/hestia.conf | grep IMAP_SYSTEM)
21-
if [ ! -z "$imap_check" ]; then
22-
WEBMAIL_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep WEBMAIL_ALIAS)
23-
if [ -z "$WEBMAIL_ALIAS_CHECK" ]; then
24-
echo "(*) Adding global webmail alias to system configuration..."
25-
sed -i "/WEBMAIL_ALIAS/d" $HESTIA/conf/hestia.conf
26-
echo "WEBMAIL_ALIAS='webmail'" >> $HESTIA/conf/hestia.conf
27-
fi
28-
fi
29+
# Generate dhparam
30+
if [ ! -e /etc/ssl/dhparam.pem ]; then
31+
echo "(*) Enabling HTTPS Strict Transport Security (HSTS) support..."
32+
mv /etc/nginx/nginx.conf $HESTIA_BACKUP/conf/
33+
cp -f $hestiacp/nginx/nginx.conf /etc/nginx/
2934

30-
# Load global variables
31-
source $HESTIA/conf/hestia.conf
32-
33-
# Load hestia main functions
34-
source /usr/local/hestia/func/main.sh
35-
36-
# Detect OS
37-
case $(head -n1 /etc/issue | cut -f 1 -d ' ') in
38-
Debian) os="debian" ;;
39-
Ubuntu) os="ubuntu" ;;
40-
esac
41-
42-
# Detect release for Debian
43-
if [ "$os" = "debian" ]; then
44-
release=$(cat /etc/debian_version|grep -o [0-9]|head -n1)
45-
VERSION='debian'
46-
elif [ "$os" = "ubuntu" ]; then
47-
release="$(lsb_release -s -r)"
48-
VERSION='ubuntu'
49-
fi
35+
# Copy dhparam
36+
cp -f $hestiacp/ssl/dhparam.pem /etc/ssl/
5037

51-
# Configure apt to retry downloading on error
52-
if [ ! -f /etc/apt/apt.conf.d/80-retries ]; then
53-
echo "APT::Acquire::Retries \"3\";" > /etc/apt/apt.conf.d/80-retries
38+
# Update DNS servers in nginx.conf
39+
dns_resolver=$(cat /etc/resolv.conf | grep -i '^nameserver' | cut -d ' ' -f2 | tr '\r\n' ' ' | xargs)
40+
sed -i "s/1.0.0.1 1.1.1.1/$dns_resolver/g" /etc/nginx/nginx.conf
5441
fi
5542

56-
# Update default page templates
57-
echo "(*) Replacing default templates and packages..."
58-
5943
# Back up default package and install latest version
6044
if [ -d $HESTIA/data/packages/ ]; then
45+
echo "(*) Replacing default packages..."
6146
cp -f $HESTIA/data/packages/default.pkg $HESTIA_BACKUP/packages/
6247
fi
6348

49+
# Back up old template files and install the latest versions
50+
if [ -d $HESTIA/data/templates/ ]; then
51+
echo "(*) Replacing default Web, DNS, and Mail templates..."
52+
cp -rf $HESTIA/data/templates $HESTIA_BACKUP/templates/
53+
$HESTIA/bin/v-update-web-templates >/dev/null 2>&1
54+
$HESTIA/bin/v-update-dns-templates >/dev/null 2>&1
55+
$HESTIA/bin/v-update-mail-templates >/dev/null 2>&1
56+
fi
57+
6458
# Remove old Office 365 template as there is a newer version with an updated name
6559
if [ -f $HESTIA/data/templates/dns/o365.tpl ]; then
6660
rm -f $HESTIA/data/templates/dns/o365.tpl
@@ -178,16 +172,16 @@ if [ ! -f /etc/cron.daily/php-session-cleanup ]; then
178172
echo "find -O3 /home/*/tmp/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
179173
echo "find -O3 $HESTIA/data/sessions/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
180174
fi
181-
chmod 755 /etc/cron.daily/php-session-cleanup
175+
chmod 755 /etc/cron.daily/php-session-cleanup
182176

183177
# Fix empty pool error message for MultiPHP
184178
php_versions=$(ls /etc/php/*/fpm -d 2>/dev/null |wc -l)
185179
if [ "$php_versions" -gt 1 ]; then
180+
echo "(*) Updating Multi-PHP configuration..."
186181
for v in $(ls /etc/php/); do
187182
if [ ! -d "/etc/php/$v/fpm/pool.d/" ]; then
188183
continue
189184
fi
190-
echo "(*) Updating Multi-PHP configuration..."
191185
cp -f $hestiacp/php-fpm/dummy.conf /etc/php/$v/fpm/pool.d/
192186
v1=$(echo "$v" | sed -e 's/[.]//')
193187
sed -i "s/9999/99$v1/g" /etc/php/$v/fpm/pool.d/dummy.conf
@@ -260,14 +254,15 @@ if [ ! -z "$WEBALIZER_CHECK" ]; then
260254
sed -i "s/STATS_SYSTEM='webalizer,awstats'/STATS_SYSTEM='awstats'/g" $HESTIA/conf/hestia.conf
261255
fi
262256

263-
# Enable SFTP chroot jail capabilities
264-
$HESTIA/bin/v-add-sys-sftp-jail no
257+
# Run sftp jail once
258+
$HESTIA/bin/v-add-sys-sftp-jail
265259

266260
# Enable SFTP subsystem for SSH
267261
sftp_subsys_enabled=$(grep -iE "^#?.*subsystem.+(sftp )?sftp-server" /etc/ssh/sshd_config)
268262
if [ ! -z "$sftp_subsys_enabled" ]; then
269263
echo "(*) Updating SFTP subsystem configuration..."
270264
sed -i -E "s/^#?.*Subsystem.+(sftp )?sftp-server/Subsystem sftp internal-sftp/g" /etc/ssh/sshd_config
265+
systemctl restart ssh
271266
fi
272267

273268
# Remove and migrate obsolete object keys
@@ -289,23 +284,3 @@ for user in `ls /usr/local/hestia/data/users/`; do
289284
done
290285
sed -i "s/\sFORCESSL=''//g" $USER_DATA/web.conf
291286
done
292-
293-
# Reset backend port
294-
if [ ! -z "$BACKEND_PORT" ]; then
295-
/usr/local/hestia/bin/v-change-sys-port $BACKEND_PORT
296-
fi
297-
298-
# Move clamav to proper location - https://goo.gl/zNuM11
299-
if [ ! -d /usr/local/hestia/web/edit/server/clamav-daemon ]; then
300-
mv /usr/local/hestia/web/edit/server/clamd /usr/local/web/edit/server/clamav-daemon
301-
fi
302-
303-
# Fix named rule for AppArmor - https://goo.gl/SPqHdq
304-
if [ "$DNS_SYSTEM" = 'bind9' ] && [ ! -f /etc/apparmor.d/local/usr.sbin.named ]; then
305-
echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2> /dev/null
306-
fi
307-
308-
# Remove obsolete ports.conf if exists.
309-
if [ -f /usr/local/hestia/data/firewall/ports.conf ]; then
310-
rm -f /usr/local/hestia/data/firewall/ports.conf
311-
fi

src/deb/hestia/postinst

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#!/bin/bash
22

3+
# Configure apt to retry downloading on error
4+
if [ ! -f /etc/apt/apt.conf.d/80-retries ]; then
5+
echo "APT::Acquire::Retries \"3\";" > /etc/apt/apt.conf.d/80-retries
6+
fi
7+
8+
# Define version check function
9+
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
10+
311
# Get package version
412
version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
513

@@ -9,13 +17,8 @@ source /usr/local/hestia/func/main.sh
917
# Load message variables
1018
source /usr/local/hestia/install/upgrade/messages.sh
1119

12-
# Run triggers only on updates
13-
if [ ! -e "/usr/local/hestia/data/users/admin" ]; then
14-
exit
15-
fi
16-
1720
# Set backup folder
18-
HESTIA_BACKUP="/root/hst_upgrade/$(date +%d%m%Y%H%M)"
21+
HESTIA_BACKUP="/root/hst_upgrade_backups/$(date +%d%m%Y%H%M)"
1922

2023
# Initialize backup folders
2124
mkdir -p $HESTIA_BACKUP/conf/
@@ -25,6 +28,11 @@ mkdir -p $HESTIA_BACKUP/templates/
2528
# Set installation source folder
2629
hestiacp="$HESTIA/install/deb"
2730

31+
# Run triggers only on updates
32+
if [ ! -e "/usr/local/hestia/data/users/admin" ]; then
33+
exit
34+
fi
35+
2836
# Clear the screen from apt output to prepare for upgrade installer experience
2937
clear
3038
welcome_message
@@ -45,7 +53,7 @@ sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
4553
echo "VERSION='$version'" >> $HESTIA/conf/hestia.conf
4654

4755
# Add upgrade notification to admin user's panel
48-
$HESTIA/bin/v-add-user-notification admin 'Upgrade complete' 'Your server has been updated to '$version'.<br>Please report any bugs on GitHub at<br><a href="https://github.com/hestiacp/hestiacp/Issues" target="_new">https://github.com/hestiacp/hestiacp/Issues</a><br><br>Have a great day!'
56+
$HESTIA/bin/v-add-user-notification admin 'Upgrade complete' 'Your server has been updated to Hestia Control Panel version '$version'.<br>Please report any bugs on GitHub at<br><a href="https://github.com/hestiacp/hestiacp/Issues" target="_new">https://github.com/hestiacp/hestiacp/Issues</a><br><br>Have a great day!'
4957

5058
# Restart services for changes to take full effect
5159
source /usr/local/hestia/install/upgrade/restart.sh

0 commit comments

Comments
 (0)