Skip to content

Commit a62bc60

Browse files
author
Kristan Kenney
committed
Fix syntax issue in upgrade scripts
1 parent a0f7e93 commit a62bc60

File tree

3 files changed

+119
-95
lines changed

3 files changed

+119
-95
lines changed

func/upgrade.sh

Lines changed: 96 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,91 +6,104 @@
66
####### Functions & Initialization #######
77
#####################################################################
88

9-
function upgrade_welcome_message() {
9+
upgrade_welcome_message() {
1010
echo
11-
echo ' _ _ _ _ ____ ____ '
12-
echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
13-
echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
14-
echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
15-
echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
16-
echo ""
17-
echo " Hestia Control Panel Upgrade Script"
18-
echo " Version: $new_version "
19-
echo "==================================================="
20-
echo ""
21-
echo "Please note that some configuration and template"
11+
echo ' _ _ _ _ ____ ____ '
12+
echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
13+
echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
14+
echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
15+
echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
16+
echo " "
17+
echo " Hestia Control Panel Software Update "
18+
echo " Version: $new_version "
19+
echo "======================================================================"
20+
echo
21+
echo "Please note that some configuration and template files may be modified"
2222
echo "files may be replaced during the upgrade process."
2323
echo ""
2424
echo "Backups of these files will be available under:"
2525
echo "$HESTIA_BACKUP/"
26-
echo ""
26+
echo
2727
echo "This process may take a few minutes, please wait..."
28-
echo ""
28+
echo
29+
echo "======================================================================"
30+
echo
2931
}
3032

31-
function upgrade_complete_message() {
33+
upgrade_complete_message() {
3234
# Add notification to panel
3335
$HESTIA/bin/v-add-user-notification admin 'Upgrade complete' 'Your server has been updated to Hestia Control Panel version '$new_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!'
3436

3537
# Echo message to console output
38+
echo
39+
echo "======================================================================"
3640
echo ""
3741
echo " Upgrade complete! Please report any bugs or issues to"
3842
echo " https://github.com/hestiacp/hestiacp/issues"
39-
echo ""
43+
echo
4044
echo " We hope that you enjoy this release of Hestia Control Panel,"
4145
echo " enjoy your day!"
42-
echo ""
46+
echo
4347
echo " Sincerely,"
4448
echo " The Hestia Control Panel development team"
45-
echo ""
49+
echo
4650
echo " www.hestiacp.com"
4751
echo " Made with love & pride by the open-source community around the world."
48-
echo ""
49-
echo ""
52+
echo
53+
echo
5054
}
5155

52-
function upgrade_init_backup() {
56+
upgrade_init_backup() {
5357
# Ensure that backup directories are created
5458
mkdir -p $HESTIA_BACKUP/conf/
5559
mkdir -p $HESTIA_BACKUP/packages/
5660
mkdir -p $HESTIA_BACKUP/templates/
5761
}
5862

59-
function upgrade_start_routine() {
63+
upgrade_start_routine() {
64+
#####################################################################
65+
####### Ensure that release branch variable exists #######
66+
#####################################################################
67+
release_branch_check=$(cat $HESTIA/conf/hestia.conf | grep RELEASE_BRANCH)
68+
if [ -z "$release_branch_check" ]; then
69+
echo "(*) Adding global release branch variable to system configuration..."
70+
sed -i "/RELEASE_BRANCH/d" $HESTIA/conf/hestia.conf
71+
echo "RELEASE_BRANCH='release'" >> $HESTIA/conf/hestia.conf
72+
fi
6073

6174
#####################################################################
6275
####### Start upgrade for pre-release builds #######
6376
#####################################################################
6477

6578
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" ]; then
66-
source $HESTIA_INSTALL_DIR/upgrade/versions/previous/0.9.8-29.sh
67-
source $HESTIA_INSTALL_DIR/upgrade/versions/previous/1.00.0-190618.sh
68-
source $HESTIA_INSTALL_DIR/upgrade/versions/previous/1.0.1.sh
79+
source $HESTIA/install/upgrade/versions/previous/0.9.8-29.sh
80+
source $HESTIA/install/upgrade/versions/previous/1.00.0-190618.sh
81+
source $HESTIA/install/upgrade/versions/previous/1.0.1.sh
6982
VERSION="1.0.1"
7083
fi
7184

7285
#####################################################################
7386
####### Start standard upgrade process #######
7487
#####################################################################
7588

89+
# Ensure that latest upgrade commands are processed if version is the same
90+
if [ $VERSION = "$new_version" ]; then
91+
echo "(!) The latest version of Hestia Control Panel ($new_version) is already installed."
92+
echo " Verifying configuration..."
93+
echo ""
94+
source $HESTIA/install/upgrade/versions/latest.sh
95+
VERSION="$new_version"
96+
fi
97+
7698
# Upgrade to Version 1.0.2
7799
if [ $VERSION = "1.0.1" ]; then
78-
source $HESTIA_INSTALL_DIR/upgrade/versions/previous/1.0.2.sh
100+
source $HESTIA/install/upgrade/versions/previous/1.0.2.sh
79101
VERSION="1.0.2"
80102
fi
81103

82104
# Upgrade to Version 1.0.3
83105
if [ $VERSION = "1.0.2" ]; then
84-
source $HESTIA_INSTALL_DIR/upgrade/versions/latest.sh
85-
VERSION="$new_version"
86-
fi
87-
88-
# Ensure that latest upgrade commands are processed if version is the same
89-
if [ $VERSION = "$new_version" ]; then
90-
echo "(!) The latest version of Hestia Control Panel ($new_version) is already installed."
91-
echo " Verifying configuration..."
92-
echo ""
93-
source $HESTIA_INSTALL_DIR/upgrade/versions/latest.sh
106+
source $HESTIA/install/upgrade/versions/latest.sh
94107
VERSION="$new_version"
95108
fi
96109

@@ -99,53 +112,61 @@ function upgrade_start_routine() {
99112
#####################################################################
100113
}
101114

102-
function upgrade_phpmyadmin() {
103-
# Define version check function
104-
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
105-
106-
pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
107-
if version_ge "${pma_release_file##*-}" "$pma_v"; then
108-
echo "(*) phpMyAdmin $pma_v or newer is already installed: ${pma_release_file##*-}, skipping update..."
109-
else
110-
# Display upgrade information
111-
echo "(*) Upgrade phpMyAdmin to v$pma_v..."
112-
[ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
113-
114-
# Download latest phpMyAdmin release
115-
wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
116-
117-
# Unpack files
118-
tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
119-
120-
# Delete file to prevent error
121-
rm -fr /usr/share/phpmyadmin/doc/html
122-
123-
# Overwrite old files
124-
cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
125-
126-
# Set config and log directory
127-
sed -i "s|define('CONFIG_DIR', '');|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
128-
sed -i "s|define('TEMP_DIR', './tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
129-
130-
# Create temporary folder and change permissions
131-
if [ ! -d /usr/share/phpmyadmin/tmp ]; then
132-
mkdir /usr/share/phpmyadmin/tmp
133-
chmod 777 /usr/share/phpmyadmin/tmp
115+
upgrade_phpmyadmin() {
116+
# Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
117+
if [ $DB_SYSTEM = "mysql" ]; then
118+
# Define version check function
119+
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
120+
121+
pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
122+
if version_ge "${pma_release_file##*-}" "$pma_v"; then
123+
echo "(*) phpMyAdmin $pma_v or newer is already installed: ${pma_release_file##*-}, skipping update..."
124+
else
125+
# Display upgrade information
126+
echo "(*) Upgrade phpMyAdmin to v$pma_v..."
127+
[ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
128+
129+
# Download latest phpMyAdmin release
130+
wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
131+
132+
# Unpack files
133+
tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
134+
135+
# Delete file to prevent error
136+
rm -fr /usr/share/phpmyadmin/doc/html
137+
138+
# Overwrite old files
139+
cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
140+
141+
# Set config and log directory
142+
sed -i "s|define('CONFIG_DIR', '');|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
143+
sed -i "s|define('TEMP_DIR', './tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
144+
145+
# Create temporary folder and change permissions
146+
if [ ! -d /usr/share/phpmyadmin/tmp ]; then
147+
mkdir /usr/share/phpmyadmin/tmp
148+
chmod 777 /usr/share/phpmyadmin/tmp
149+
fi
150+
151+
# Clean up source files
152+
rm -fr phpMyAdmin-$pma_v-all-languages
153+
rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
134154
fi
135-
136-
# Clean up source files
137-
rm -fr phpMyAdmin-$pma_v-all-languages
138-
rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
139155
fi
140156
}
141157

142-
function upgrade_set_version() {
158+
upgrade_get_version() {
159+
# Retrieve new version number for Hestia Control Panel from .deb package
160+
new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
161+
}
162+
163+
upgrade_set_version() {
143164
# Set new version number in hestia.conf
144165
sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
145166
echo "VERSION='$new_version'" >> $HESTIA/conf/hestia.conf
146167
}
147168

148-
function upgrade_rebuild_users() {
169+
upgrade_rebuild_users() {
149170
for user in `ls /usr/local/hestia/data/users/`; do
150171
echo "(*) Rebuilding domains and account for user: $user..."
151172
if [ ! -z $WEB_SYSTEM ]; then
@@ -160,7 +181,7 @@ function upgrade_rebuild_users() {
160181
done
161182
}
162183

163-
function upgrade_restart_services() {
184+
upgrade_restart_services() {
164185
echo "(*) Restarting services..."
165186
if [ ! -z $MAIL_SYSTEM ]; then
166187
$BIN/v-restart-mail $restart

src/deb/hestia/postinst

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

3-
# Define global functions, upgrade functions, and necessary variables
4-
source $HESTIA/func/main.sh
5-
source $HESTIA/func/upgrade.sh
3+
###############################################################
4+
# Initialize functions/variables #
5+
###############################################################
6+
source /usr/local/hestia/conf/hestia.conf
7+
source /usr/local/hestia/func/main.sh
8+
source /usr/local/hestia/func/upgrade.sh
9+
10+
###############################################################
11+
# Set new version numbers for packages #
12+
###############################################################
13+
# Hestia Control Panel
14+
new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
15+
16+
# phpMyAdmin
17+
pma_v='4.9.0.1'
18+
19+
###############################################################
20+
# Begin standard upgrade routines #
21+
###############################################################
622

723
# Initialize backup directories
824
upgrade_init_backup
@@ -17,13 +33,16 @@ upgrade_start_routine
1733
# Upgrade phpMyAdmin if applicable
1834
upgrade_phpmyadmin
1935

36+
# Set new version number in hestia.conf
37+
upgrade_set_version
38+
2039
# Perform account and domain rebuild to ensure configuration files are correct
2140
upgrade_rebuild_users
2241

2342
# Restart necessary services for changes to take full effect
2443
upgrade_restart_services
2544

2645
# Add upgrade notification to admin user's panel and display completion message
27-
upgrade_message_complete
46+
upgrade_complete_message
2847

2948
exit 0

src/deb/hestia/preinst

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,3 @@ if [ ! -f /etc/apt/apt.conf.d/80-retries ]; then
1010
echo "APT::Acquire::Retries \"3\";" > /etc/apt/apt.conf.d/80-retries
1111
fi
1212

13-
# Add release branch system configuration if non-existent
14-
release_branch_check=$(cat $HESTIA/conf/hestia.conf | grep RELEASE_BRANCH)
15-
if [ -z "$release_branch_check" ]; then
16-
echo "(*) Adding global release branch variable to system configuration..."
17-
sed -i "/RELEASE_BRANCH/d" $HESTIA/conf/hestia.conf
18-
echo "RELEASE_BRANCH='release'" >> $HESTIA/conf/hestia.conf
19-
fi
20-
21-
# Set new version number for Hestia Control Panel
22-
new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
23-
24-
# Set new version number for phpMyAdmin
25-
pma_v='4.9.0.1'
26-
27-
# Load hestia.conf
28-
source /usr/local/hestia/conf/hestia.conf

0 commit comments

Comments
 (0)