Просмотр исходного кода

Fix syntax issue in upgrade scripts

Kristan Kenney 6 лет назад
Родитель
Сommit
a62bc60b7f
3 измененных файлов с 119 добавлено и 95 удалено
  1. 96 75
      func/upgrade.sh
  2. 23 4
      src/deb/hestia/postinst
  3. 0 16
      src/deb/hestia/preinst

+ 96 - 75
func/upgrade.sh

@@ -6,66 +6,79 @@
 #######                Functions & Initialization             #######
 #####################################################################
 
-function upgrade_welcome_message() {
+upgrade_welcome_message() {
     echo
-    echo '     _   _           _   _        ____ ____        '
-    echo '    | | | | ___  ___| |_(_) __ _ / ___|  _ \       '
-    echo '    | |_| |/ _ \/ __| __| |/ _` | |   | |_) |      '
-    echo '    |  _  |  __/\__ \ |_| | (_| | |___|  __/       '
-    echo '    |_| |_|\___||___/\__|_|\__,_|\____|_|          '
-    echo ""
-    echo "       Hestia Control Panel Upgrade Script"
-    echo "                 Version: $new_version             "
-    echo "==================================================="
-    echo ""
-    echo "Please note that some configuration and template"
+    echo '               _   _           _   _        ____ ____                 '
+    echo '              | | | | ___  ___| |_(_) __ _ / ___|  _ \                '
+    echo '              | |_| |/ _ \/ __| __| |/ _` | |   | |_) |               '
+    echo '              |  _  |  __/\__ \ |_| | (_| | |___|  __/                '
+    echo '              |_| |_|\___||___/\__|_|\__,_|\____|_|                   '
+    echo "                                                                      "
+    echo "                 Hestia Control Panel Software Update                 "
+    echo "                         Version: $new_version                        "
+    echo "======================================================================"
+    echo
+    echo "Please note that some configuration and template files may be modified"
     echo "files may be replaced during the upgrade process."
     echo ""
     echo "Backups of these files will be available under:"
     echo "$HESTIA_BACKUP/"
-    echo ""
+    echo
     echo "This process may take a few minutes, please wait..."
-    echo ""
+    echo
+    echo "======================================================================"
+    echo
 }
 
-function upgrade_complete_message() {
+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 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!'
 
     # Echo message to console output
+    echo
+    echo "======================================================================"
     echo ""
     echo "    Upgrade complete! Please report any bugs or issues to"
     echo "    https://github.com/hestiacp/hestiacp/issues"
-    echo ""
+    echo
     echo "    We hope that you enjoy this release of Hestia Control Panel,"
     echo "    enjoy your day!"
-    echo ""
+    echo
     echo "    Sincerely,"
     echo "    The Hestia Control Panel development team"
-    echo ""
+    echo
     echo "    www.hestiacp.com"
     echo "    Made with love & pride by the open-source community around the world."
-    echo ""
-    echo ""
+    echo
+    echo
 }
 
-function upgrade_init_backup() {
+upgrade_init_backup() {
     # Ensure that backup directories are created
     mkdir -p $HESTIA_BACKUP/conf/
     mkdir -p $HESTIA_BACKUP/packages/
     mkdir -p $HESTIA_BACKUP/templates/
 }
 
-function upgrade_start_routine() {
+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..."
+        sed -i "/RELEASE_BRANCH/d" $HESTIA/conf/hestia.conf
+        echo "RELEASE_BRANCH='release'" >> $HESTIA/conf/hestia.conf
+    fi
 
     #####################################################################
     #######         Start upgrade for pre-release builds          #######
     #####################################################################
 
     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
-        source $HESTIA_INSTALL_DIR/upgrade/versions/previous/0.9.8-29.sh
-        source $HESTIA_INSTALL_DIR/upgrade/versions/previous/1.00.0-190618.sh
-        source $HESTIA_INSTALL_DIR/upgrade/versions/previous/1.0.1.sh
+        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"
     fi
 
@@ -73,24 +86,24 @@ function upgrade_start_routine() {
     #######             Start standard upgrade process            #######
     #####################################################################
 
+    # 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 ($new_version) is already installed."
+        echo "    Verifying configuration..."
+        echo ""
+        source $HESTIA/install/upgrade/versions/latest.sh
+        VERSION="$new_version"
+    fi
+
     # Upgrade to Version 1.0.2
     if [ $VERSION = "1.0.1" ]; then
-        source $HESTIA_INSTALL_DIR/upgrade/versions/previous/1.0.2.sh
+        source $HESTIA/install/upgrade/versions/previous/1.0.2.sh
         VERSION="1.0.2"
     fi
 
     # Upgrade to Version 1.0.3
     if [ $VERSION = "1.0.2" ]; then
-        source $HESTIA_INSTALL_DIR/upgrade/versions/latest.sh
-        VERSION="$new_version"
-    fi
-
-    # 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 ($new_version) is already installed."
-        echo "    Verifying configuration..."
-        echo ""
-        source $HESTIA_INSTALL_DIR/upgrade/versions/latest.sh
+        source $HESTIA/install/upgrade/versions/latest.sh
         VERSION="$new_version"
     fi
 
@@ -99,53 +112,61 @@ function upgrade_start_routine() {
     #####################################################################
 }
 
-function upgrade_phpmyadmin() {
-    # 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 $pma_v or newer is already installed: ${pma_release_file##*-}, skipping update..."
-    else
-        # Display upgrade information
-        echo "(*) Upgrade phpMyAdmin to 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', '');|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
-        sed -i "s|define('TEMP_DIR', './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
+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 $pma_v or newer is already installed: ${pma_release_file##*-}, skipping update..."
+        else
+            # Display upgrade information
+            echo "(*) Upgrade phpMyAdmin to 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', '');|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
+            sed -i "s|define('TEMP_DIR', './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
-
-        # Clean up source files
-        rm -fr phpMyAdmin-$pma_v-all-languages
-        rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
     fi
 }
 
-function upgrade_set_version() {
+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='$new_version'" >> $HESTIA/conf/hestia.conf
 }
 
-function upgrade_rebuild_users() {
+upgrade_rebuild_users() {
     for user in `ls /usr/local/hestia/data/users/`; do
         echo "(*) Rebuilding domains and account for user: $user..."
         if [ ! -z $WEB_SYSTEM ]; then
@@ -160,7 +181,7 @@ function upgrade_rebuild_users() {
     done
 }
 
-function upgrade_restart_services() {
+upgrade_restart_services() {
     echo "(*) Restarting services..."
     if [ ! -z $MAIL_SYSTEM ]; then
         $BIN/v-restart-mail $restart

+ 23 - 4
src/deb/hestia/postinst

@@ -1,8 +1,24 @@
 #!/bin/bash
 
-# Define global functions, upgrade functions, and necessary variables
-source $HESTIA/func/main.sh
-source $HESTIA/func/upgrade.sh
+###############################################################
+#                Initialize functions/variables               #
+###############################################################
+source /usr/local/hestia/conf/hestia.conf
+source /usr/local/hestia/func/main.sh
+source /usr/local/hestia/func/upgrade.sh
+
+###############################################################
+#             Set new version numbers for packages            #
+###############################################################
+# Hestia Control Panel
+new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
+
+# phpMyAdmin
+pma_v='4.9.0.1'
+
+###############################################################
+#               Begin standard upgrade routines               #
+###############################################################
 
 # Initialize backup directories
 upgrade_init_backup
@@ -17,6 +33,9 @@ upgrade_start_routine
 # Upgrade phpMyAdmin if applicable
 upgrade_phpmyadmin
 
+# Set new version number in hestia.conf
+upgrade_set_version
+
 # Perform account and domain rebuild to ensure configuration files are correct
 upgrade_rebuild_users
 
@@ -24,6 +43,6 @@ upgrade_rebuild_users
 upgrade_restart_services
 
 # Add upgrade notification to admin user's panel and display completion message
-upgrade_message_complete
+upgrade_complete_message
 
 exit 0

+ 0 - 16
src/deb/hestia/preinst

@@ -10,19 +10,3 @@ if [ ! -f /etc/apt/apt.conf.d/80-retries ]; then
     echo "APT::Acquire::Retries \"3\";" > /etc/apt/apt.conf.d/80-retries
 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='release'" >> $HESTIA/conf/hestia.conf
-fi
-
-# Set new version number for Hestia Control Panel
-new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
-
-# Set new version number for phpMyAdmin
-pma_v='4.9.0.1'
-
-# Load hestia.conf
-source /usr/local/hestia/conf/hestia.conf