Browse Source

Refactor v-update-sys-themes and add comments

Kristan Kenney 6 years ago
parent
commit
1df30bad61
2 changed files with 87 additions and 53 deletions
  1. 0 53
      bin/v-update-sys-theme
  2. 87 0
      bin/v-update-sys-themes

+ 0 - 53
bin/v-update-sys-theme

@@ -1,53 +0,0 @@
-#!/bin/bash
-
-quiet=$1
-
-source $HESTIA/func/main.sh
-source $HESTIA/conf/hestia.conf
-
-welcome_message() {
-    echo "********************************************************"
-    echo "*  Hestia Control Panel - User Interface Theme Updater *"
-    echo "********************************************************"
-    echo "     This script will update the themes currently       "
-    echo " available on your system, which may include bug fixes  "
-    echo " and improvements from our development team which are   "
-    echo "    intended to provide a user better experience        "
-    echo "********************************************************"
-    echo "       Proceed with theme update installation?          "
-    echo "                       [Y/n]                            "
-    echo ""
-}
-
-if [ "$quiet" ]; then 
-    answer="y"
-else
-    welcome_message
-    read -p "" answer
-fi
-
-if [ "$answer" = "y" ] || [ "$answer" = "Y" ] || [ "$answer" = "yes" ]; then
-    echo ""
-    echo "Updating system base theme..."
-    if [ -e "$HESTIA/web/css/styles.min.css" ]; then
-        rm -f "$HESTIA/web/css/styles.min.css"
-    fi
-    wget -O $HESTIA/web/css/styles.min.css $HESTIA_GIT_REPO/$RELEASE_BRANCH/web/css/styles.min.css --show-progress --progress=bar:force --limit-rate=3m 
-
-    echo "Updating included themes..."
-    for themefile in `ls $HESTIA/install/deb/themes`; do
-
-    if [ -e $themefile ]; then
-        rm -f $themefile
-    fi
-    echo "Downloading $themefile..."
-    wget -O $HESTIA_INSTALL_DIR/themes/$themefile $HESTIA_GIT_REPO/$RELEASE_BRANCH/install/deb/themes/$themefile --show-progress --progress=bar:force --limit-rate=3m
-    done
-
-    if [ "$THEME" != "default" ]; then
-        echo "Applying updated system interface theme..."
-        $BIN/v-change-sys-theme $THEME
-    fi
-else
-    echo "Update process aborted."
-fi

+ 87 - 0
bin/v-update-sys-themes

@@ -0,0 +1,87 @@
+#!/bin/bash
+
+# v-update-sys-themes
+# info: update system themes
+# options: quiet
+#
+# The function is for updating system theme css files from
+# Hestia Control Panel's GitHub repository
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+branch=$1
+quiet=$2
+
+# Import main functions and variables for release branch
+# and system theme currently in use
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
+
+# Check for release branch override
+if [ -z "$branch" ]; then
+    theme_branch="$RELEASE_BRANCH"
+else
+    if [ "$RELEASE_BRANCH" != "$branch" ]; then
+        theme_branch="$branch"
+    else
+        theme_branch="$RELEASE_BRANCH"
+    fi
+fi
+
+# Catch in the event that v-update-sys-themes yes is specified
+if [ "$branch" = "yes" ] || [ "$branch" = "y" ]; then
+    answer_set="y"
+    theme_branch="$RELEASE_BRANCH"
+fi
+
+# Check for presence of quiet flag and skip the
+# welcomwe/warning prompt that is displayed when running
+# without any switches/flags.
+if [ -z "$answer_set" ]; then
+    if [ "$quiet" ]; then 
+        answer="y"
+    else
+        read -p "Proceed with theme update installation? [Y/n] " answer
+    fi
+else
+    answer="y"
+fi
+
+# Download the base system theme and update each CSS file present in the themes folder
+if [ "$answer" = "y" ] || [ "$answer" = "Y" ] || [ "$answer" = "yes" ]; then
+    echo ""
+    echo "Hestia Control Panel UI Theme Updater"
+    echo "============================================"
+    echo "Version:          $VERSION"
+    echo "Release Branch:   $RELEASE_BRANCH"
+    echo "Theme Branch:     $theme_branch"
+    echo "============================================"
+    echo ""
+    echo "(*) Updating system base theme..."
+    if [ -e "$HESTIA/web/css/styles.min.css" ]; then
+        rm -f "$HESTIA/web/css/styles.min.css"
+    fi
+
+    wget $HESTIA_GIT_REPO/$theme_branch/web/css/styles.min.css -q -O $HESTIA/web/css/styles.min.css --show-progress --progress=bar:force --limit-rate=3m
+    echo ""
+    echo "(*) Updating included themes..."
+    for themefile in `ls $HESTIA/install/deb/themes`; do
+
+    if [ -e $themefile ]; then
+        rm -f $themefile
+    fi
+    echo "(-) Downloading $themefile..."
+    wget $HESTIA_GIT_REPO/$theme_branch/install/deb/themes/$themefile -q -O $HESTIA_INSTALL_DIR/themes/$themefile --show-progress --progress=bar:force --limit-rate=3m
+    done
+
+    # If the system theme is not the default, run v-change-sys-theme to delete the old CSS file and replace it with the new one which was just downloaded.
+    if [ "$THEME" != "default" ]; then
+        echo "(*) Applying updated system interface theme..."
+        $BIN/v-change-sys-theme $THEME
+    fi
+else
+    echo "Update process aborted."
+fi