瀏覽代碼

Use exit codes instead of output

Ernesto Nicolás Carrea 5 年之前
父節點
當前提交
1e401489d1
共有 41 個文件被更改,包括 171 次插入217 次删除
  1. 17 15
      bin/hestia
  2. 2 3
      bin/module/apache/install.inc
  3. 2 3
      bin/module/apache/remove.inc
  4. 3 4
      bin/module/api/install.inc
  5. 3 4
      bin/module/api/remove.inc
  6. 3 4
      bin/module/awstats/install.inc
  7. 5 6
      bin/module/awstats/remove.inc
  8. 3 4
      bin/module/clamav/exim-integration/disable.inc
  9. 3 4
      bin/module/clamav/exim-integration/enable.inc
  10. 3 5
      bin/module/clamav/install.inc
  11. 4 6
      bin/module/clamav/remove.inc
  12. 3 4
      bin/module/dovecot/install.inc
  13. 4 5
      bin/module/dovecot/remove.inc
  14. 3 4
      bin/module/dummy/install.inc
  15. 3 4
      bin/module/dummy/remove.inc
  16. 4 7
      bin/module/exim/install.inc
  17. 3 4
      bin/module/exim/remove.inc
  18. 10 15
      bin/module/func.inc
  19. 4 7
      bin/module/info.inc
  20. 1 1
      bin/module/install.inc
  21. 4 9
      bin/module/list.inc
  22. 2 3
      bin/module/mariadb/install.inc
  23. 5 8
      bin/module/mariadb/remove.inc
  24. 2 3
      bin/module/nginx/install.inc
  25. 2 3
      bin/module/nginx/remove.inc
  26. 11 12
      bin/module/php/add.inc
  27. 9 10
      bin/module/php/del.inc
  28. 4 5
      bin/module/php/install.inc
  29. 4 5
      bin/module/php/list.inc
  30. 3 3
      bin/module/php/remove.inc
  31. 1 1
      bin/module/remove.inc
  32. 3 4
      bin/module/spamassassin/exim-integration/disable.inc
  33. 3 4
      bin/module/spamassassin/exim-integration/enable.inc
  34. 3 5
      bin/module/spamassassin/install.inc
  35. 5 7
      bin/module/spamassassin/remove.inc
  36. 3 4
      bin/module/vsftpd/install.inc
  37. 4 5
      bin/module/vsftpd/remove.inc
  38. 3 4
      bin/module/web/setup.inc
  39. 1 1
      bin/package/install/mail-server.inc
  40. 1 1
      bin/package/install/web-server.inc
  41. 15 11
      func/osal.sh

+ 17 - 15
bin/hestia

@@ -8,8 +8,8 @@ source $HESTIA/conf/hestia.conf
 
 hestia() {
     # Search for command file
-    cmd_name=''
-    cmd_file=''
+    local cmd_name=''
+    local cmd_file=''
     for arg in "$@"
     do
         # FIXME: secutirity (what is $arg is something like ../../../malicious_code)
@@ -88,18 +88,20 @@ hestia() {
     [ "$params" ] && params="${params:1}"
 
     if [ $cmd_file ]; then
-        #echo "Command file          : $cmd_file"
-        #echo "Command type          : $cmd_type"
-        #echo "Command function name : hestia_${cmd_name}()"
-        #echo "Remaining arguments   : $@"
-        #echo "Parameters used       : $params"
-        #echo "Parameter values      : "
-        #for param in $params; do
-        #    echo "    --$param ${!param}"
-        #done
-        #echo ""
-        #echo "*** Now the command itself:"
-        #echo ""
+        if [ "$HESTIA_DEBUG" ]; then
+            echo "Command file          : $cmd_file"
+            echo "Command type          : $cmd_type"
+            echo "Command function name : hestia_${cmd_name}()"
+            echo "Remaining arguments   : $@"
+            echo "Parameters used       : $params"
+            echo "Parameter values      : "
+            for param in $params; do
+                echo "    --$param ${!param}"
+            done
+            echo ""
+            echo "*** Now the command itself:"
+            echo ""
+        fi
 
         if [ "$cmd_type" = 'include' ]; then
             source $cmd_file
@@ -109,7 +111,7 @@ hestia() {
         fi
     else
         echo "Hestia: Unrecognized command: $@"
-        exit 1
+        return 1
     fi
 }
 

+ 2 - 3
bin/module/apache/install.inc

@@ -3,10 +3,9 @@
 hestia_module_apache_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled apache)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'apache' && [ ! "$param_force" ]; then
         echo "Apache module is already installed. See 'hestia module info apache'."
-        exit 1
+        return 1
     fi
 
     echo "Installing Apache module..."

+ 2 - 3
bin/module/apache/remove.inc

@@ -3,10 +3,9 @@
 hestia_module_apache_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled apache)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'apache' && [ ! "$param_force" ]; then
         echo "Apache module is not installed. See 'hestia module info apache'."
-        exit 1
+        return 1
     fi
 
     echo "Removing Apache module..."

+ 3 - 4
bin/module/api/install.inc

@@ -3,10 +3,9 @@
 hestia_module_api_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled api)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'api' && [ ! "$param_force" ]; then
         echo "API module is already installed. See 'hestia module info api'."
-        exit 1
+        return 1
     fi
 
     echo "Installing API module..."
@@ -18,5 +17,5 @@ hestia_module_api_install() {
     osal_kv_write $HESTIA_CONF_MODULES/api.conf 'variant' 'api'
     osal_kv_write $HESTIA_CONF_MODULES/api.conf 'version' '1'
 
-    exit 0
+    return 0
 }

+ 3 - 4
bin/module/api/remove.inc

@@ -3,10 +3,9 @@
 hestia_module_api_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled api)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'api' && [ ! "$param_force" ]; then
         echo "API module is not installed. See 'hestia module info api'."
-        exit 1
+        return 1
     fi
 
     echo "Removing API module..."
@@ -18,5 +17,5 @@ hestia_module_api_remove() {
     osal_kv_write $HESTIA_CONF_MODULES/api.conf 'variant' ''
     osal_kv_write $HESTIA_CONF_MODULES/api.conf 'version' '0'
 
-    exit 0
+    return 0
 }

+ 3 - 4
bin/module/awstats/install.inc

@@ -3,10 +3,9 @@
 hestia_module_awstats_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled webstats)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'webstats' && [ ! "$param_force" ]; then
         echo "Stats module is already installed. See 'hestia module info webstats'."
-        exit 1
+        return 1
     fi
 
     echo "Installing web stats (Awstats) module..."
@@ -27,5 +26,5 @@ hestia_module_awstats_install() {
     osal_kv_write $HESTIA_CONF_MODULES/webstats.conf 'variant' 'awstats'
     osal_kv_write $HESTIA_CONF_MODULES/webstats.conf 'version' '1'
 
-    exit 0
+    return 0
 }

+ 5 - 6
bin/module/awstats/remove.inc

@@ -3,16 +3,15 @@
 hestia_module_awstats_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled webstats)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'webstats' && [ ! "$param_force" ]; then
         echo "Web stats module is not installed. See 'hestia module info webstats'."
-        exit 1
+        return 1
     fi
 
-    module_variant=$(hestia_module_getvariant webstats)
+    module_variant=$(hestia_module_getvariant 'webstats')
     if [ "$module_variant" != 'awstats' ] && [ ! "$param_force" ]; then
         echo "The installed web stats module is not Awstats. See 'hestia module info webstats'."
-        exit 1
+        return 1
     fi
 
     echo "Removing web stats (Awstats) module..."
@@ -28,5 +27,5 @@ hestia_module_awstats_remove() {
     osal_kv_write $HESTIA_CONF_MODULES/webstats.conf 'variant' ''
     osal_kv_write $HESTIA_CONF_MODULES/webstats.conf 'version' '0'
 
-    exit 0
+    return 0
 }

+ 3 - 4
bin/module/clamav/exim-integration/disable.inc

@@ -3,16 +3,15 @@
 hestia_module_clamav_exim-integration_disable() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mta)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'mta' && [ ! "$param_force" ]; then
         echo "MTA module is not installed. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant mta)
     if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
         echo "The installed MTA module is not Exim. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     echo "Disabling Exim-ClamAV integration..."

+ 3 - 4
bin/module/clamav/exim-integration/enable.inc

@@ -3,16 +3,15 @@
 hestia_module_clamav_exim-integration_enable() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mta)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'mta' && [ ! "$param_force" ]; then
         echo "MTA module is not installed. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant mta)
     if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
         echo "The installed MTA module is not Exim. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     echo "Enabling Exim-ClamAV integration..."

+ 3 - 5
bin/module/clamav/install.inc

@@ -3,10 +3,9 @@
 hestia_module_clamav_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled antivirus)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'antivirus' && [ ! "$param_force" ]; then
         echo "Antivirus module is already installed. See 'hestia module info antivirus'."
-        exit 1
+        return 1
     fi
 
     echo "Installing antivirus (ClamAV) module..."
@@ -58,8 +57,7 @@ hestia_module_clamav_install() {
     osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'version' '1'
     osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'service_name' $OSAL_SERVICE_CLAMAV
 
-    exim_installed=$(hestia_module_variant_installed 'mta' 'exim')
-    if [ "$exim_installed" ]; then
+    if hestia_module_variant_installed 'mta' 'exim'; then
         $BIN/hestia module clamav exim-integration enable
     fi
 }

+ 4 - 6
bin/module/clamav/remove.inc

@@ -3,22 +3,20 @@
 hestia_module_clamav_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled antivirus)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'antivirus' && [ ! "$param_force" ]; then
         echo "antivirus module is not installed. See 'hestia module info antivirus'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant antivirus)
     if [ "$module_variant" != 'clamav' ] && [ ! "$param_force" ]; then
         echo "The installed antivirus module is not ClamAV. See 'hestia module info antivirus'."
-        exit 1
+        return 1
     fi
 
     echo "Removing antivirus (ClamAV) module..."
 
-    exim_installed=$(hestia_module_variant_installed 'mta' 'exim')
-    if [ "$exim_installed" ]; then
+    if hestia_module_variant_installed 'mta' 'exim'; then
         $BIN/hestia module clamav exim-integration disable
     fi
 

+ 3 - 4
bin/module/dovecot/install.inc

@@ -3,10 +3,9 @@
 hestia_module_dovecot_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled imap)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'imap' && [ ! "$param_force" ]; then
         echo "IMAP module is already installed. See 'hestia module info imap'."
-        exit 1
+        return 1
     fi
 
     echo "Installing IMAP (Dovecot) module..."
@@ -37,5 +36,5 @@ hestia_module_dovecot_install() {
     osal_kv_write $HESTIA_CONF_MODULES/imap.conf 'version' '1'
     osal_kv_write $HESTIA_CONF_MODULES/imap.conf 'service_name' $OSAL_PKG_DOVECOT
 
-    exit 0
+    return 0
 }

+ 4 - 5
bin/module/dovecot/remove.inc

@@ -3,16 +3,15 @@
 hestia_module_dovecot_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled imap)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'imap' && [ ! "$param_force" ]; then
         echo "IMAP module is not installed. See 'hestia module info imap'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant imap)
     if [ "$module_variant" != 'dovecot' ] && [ ! "$param_force" ]; then
         echo "The installed IMAP module is not Dovecot. See 'hestia module info imap'."
-        exit 1
+        return 1
     fi
 
     echo "Removing IMAP (Dovecot) module..."
@@ -32,5 +31,5 @@ hestia_module_dovecot_remove() {
     osal_kv_write $HESTIA_CONF_MODULES/imap.conf 'variant' ''
     osal_kv_write $HESTIA_CONF_MODULES/imap.conf 'version' '0'
 
-    exit 0
+    return 0
 }

+ 3 - 4
bin/module/dummy/install.inc

@@ -3,10 +3,9 @@
 hestia_module_dummy_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled dummy)
-    if [ "$module_installed" ]; then
+    if hestia_module_isinstalled 'dummy'; then
         echo "Dummy module is already installed. See 'hestia module info dummy'."
-        exit 1
+        return 1
     fi
 
     echo "Installing Dummy module..."
@@ -17,7 +16,7 @@ hestia_module_dummy_install() {
     osal_kv_write $HESTIA_CONF_MODULES/dummy.conf 'variant' 'crash-test-dummy'
     osal_kv_write $HESTIA_CONF_MODULES/dummy.conf 'version' '4'
 
-    exit 0
+    return 0
 }
 
 # If this files is _not_ being sourced, act immediately

+ 3 - 4
bin/module/dummy/remove.inc

@@ -3,10 +3,9 @@
 hestia_module_dummy_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled dummy)
-    if [ ! "$module_installed" ]; then
+    if ! hestia_module_isinstalled 'dummy'; then
         echo "Dummy module is not installed. See 'hestia module info dummy'."
-        exit 1
+        return 1
     fi
 
     echo "Removing Dummy module..."
@@ -17,7 +16,7 @@ hestia_module_dummy_remove() {
     osal_kv_write $HESTIA_CONF_MODULES/dummy.conf 'variant' ''
     osal_kv_write $HESTIA_CONF_MODULES/dummy.conf 'version' '0'
 
-    exit 0
+    return 0
 }
 
 # If this files is _not_ being sourced, act immediately

+ 4 - 7
bin/module/exim/install.inc

@@ -3,10 +3,9 @@
 hestia_module_exim_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mta)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'mta' && [ ! "$param_force" ]; then
         echo "MTA module is already installed. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     echo "Installing MTA (Exim) module..."
@@ -57,14 +56,12 @@ hestia_module_exim_install() {
     done
 
     # Setup ClamAv integration
-    clamav_installed=$(hestia_module_variant_installed 'antivirus' 'clamav')
-    if [ "$clamav_installed" ]; then
+    if hestia_module_variant_installed 'antivirus' 'clamav'; then
         $BIN/hestia module clamav exim-integration enable
     fi
 
     # Setup SpamAssassin integration
-    spamassassin_installed=$(hestia_module_variant_installed 'antispam' 'spamassassin')
-    if [ "$spamassassin_installed" ]; then
+    if hestia_module_variant_installed 'antispam' 'spamassassin'; then
         $BIN/hestia module spamassassin exim-integration enable
     fi
 }

+ 3 - 4
bin/module/exim/remove.inc

@@ -3,16 +3,15 @@
 hestia_module_exim_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mta)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'mta' && [ ! "$param_force" ]; then
         echo "MTA module is not installed. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant mta)
     if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
         echo "The installed MTA module is not Exim. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     echo "Removing MTA (Exim) module..."

+ 10 - 15
bin/module/func.inc

@@ -3,36 +3,31 @@
 HESTIA_CONF_MODULES=$HESTIA/conf/modules
 mkdir -p $HESTIA_CONF_MODULES
 
-# Returns 1 if module is installed
+# Tests if module is installed
 hestia_module_isinstalled() {
     osal_kv_read_bool $HESTIA_CONF_MODULES/${1}.conf 'installed'
 }
 
-# Returns 1 if module is installed and enabled
-hestia_module_isenabled() {
-    is_installed=$(osal_kv_read_bool $HESTIA_CONF_MODULES/${1}.conf 'installed')
-    is_enabled=$(osal_kv_read_bool $HESTIA_CONF_MODULES/${1}.conf 'enabled')
-    if [ "$is_installed" ] && [ "$is_enabled" ]; then
-        echo 1
-    fi
-}
-
+# Returns module version
 hestia_module_getversion() {
     osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'version'
 }
 
+# Returns module installed variant
 hestia_module_getvariant() {
     osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'variant'
 }
 
+# Tests if a specific variant of a module is installed
 hestia_module_variant_installed() {
-    module_installed=$(hestia_module_isinstalled $1)
+    local module_installed=$(hestia_module_isinstalled $1 && echo 1)
     if [ "$module_installed" ]; then
-        module_variant=$(hestia_module_getvariant $1)
+        local module_variant=$(hestia_module_getvariant $1)
         if [ "$module_variant" = "$2" ]; then
-            echo 1
+            return 0
         fi
     fi
+    return 1
 }
 
 # Schedules a service restart (when doing multiple actions)
@@ -57,8 +52,8 @@ hestia_module_service_restart_restart() {
 # Backup config files (usually prior to module install)
 # hestia_config_backup 'prefix' file1 file2 file3 ...
 hestia_config_backup() {
-    dest=$HESTIA/data/backup/
-    filename=${1}-$(date +%Y%m%d%H%M%S)
+    local dest=$HESTIA/data/backup/
+    local filename=${1}-$(date +%Y%m%d%H%M%S)
     shift
 
     mkdir -p $dest

+ 4 - 7
bin/module/info.inc

@@ -3,18 +3,15 @@
 hestia_module_info() {
     source $HESTIA/bin/module/func.inc
 
-    modulename=$1
+    local modulename=$1
     echo "Module name     : $modulename"
     
-    module_installed=$(hestia_module_isinstalled $modulename)
-    if [ "$module_installed" ]; then
-        module_enabled=$(hestia_module_isenabled $modulename)
-        module_variant=$(hestia_module_getvariant $modulename)
-        module_version=$(hestia_module_getversion $modulename)
+    if hestia_module_isinstalled $modulename; then
+        local module_variant=$(hestia_module_getvariant $modulename)
+        local module_version=$(hestia_module_getversion $modulename)
 
         echo "Installed       : yes"
         echo "Description     : $(osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'description')"
-        echo "Enabled         : $(osal_bool_tostring $module_enabled)"
         echo "Variant         : $module_variant"
         echo "Version         : $module_version"
     else

+ 1 - 1
bin/module/install.inc

@@ -7,6 +7,6 @@ hestia_module_install() {
         $BIN/hestia module $module_name install "$@"
     else
         echo "Usage: module install module_name"
-        exit 0
+        return 0
     fi
 }

+ 4 - 9
bin/module/list.inc

@@ -4,16 +4,11 @@ hestia_module_list() {
     source $HESTIA/bin/module/func.inc
 
     for conf_file in $HESTIA_CONF_MODULES/*.conf; do
-        mod_name=$(basename $conf_file .conf)
-        mod_descr=$(osal_kv_read ${conf_file} 'description')
+        local mod_name=$(basename $conf_file .conf)
+        local mod_descr=$(osal_kv_read ${conf_file} 'description')
 
-        module_installed=$(hestia_module_isinstalled $mod_name)
-        module_enabled=$(hestia_module_isenabled $mod_name)
-
-        if [ "$module_installed" ]; then
-            if [ "$module_enabled" ] || [ "$param_all" ]; then
-                echo "$mod_name: $mod_descr"
-            fi
+        if hestia_module_isinstalled $mod_name; then
+            echo "$mod_name: $mod_descr"
         fi
     done
 }

+ 2 - 3
bin/module/mariadb/install.inc

@@ -3,10 +3,9 @@
 hestia_module_mariadb_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mydb)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'mydb' && [ ! "$param_force" ]; then
         echo "MySQL/MariaDB database module is already installed. See 'hestia module info mydb'."
-        exit 1
+        return 1
     fi
 
     echo "Installing database (MariaDB) module..."

+ 5 - 8
bin/module/mariadb/remove.inc

@@ -3,27 +3,24 @@
 hestia_module_exim_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mta)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'mta' && [ ! "$param_force" ]; then
         echo "MTA module is not installed. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant mta)
     if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
         echo "The installed MTA module is not Exim. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     echo "Removing MTA (Exim) module..."
 
-    clamav_installed=$(hestia_module_variant_installed 'antivirus' 'clamav')
-    if [ "$clamav_installed" ]; then
+    if hestia_module_variant_installed 'antivirus' 'clamav'; then
         $BIN/hestia module clamav exim-integration disable
     fi
 
-    spamassassin_installed=$(hestia_module_variant_installed 'antispam' 'spamassassin')
-    if [ "$spamassassin_installed" ]; then
+    if hestia_module_variant_installed 'antispam' 'spamassassin'; then
         $BIN/hestia module spamassassin exim-integration disable
     fi
 

+ 2 - 3
bin/module/nginx/install.inc

@@ -3,10 +3,9 @@
 hestia_module_nginx_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled nginx)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'nginx' && [ ! "$param_force" ]; then
         echo "Nginx module is already installed. See 'hestia module info nginx'."
-        exit 1
+        return 1
     fi
 
     echo "Installing Nginx module..."

+ 2 - 3
bin/module/nginx/remove.inc

@@ -3,10 +3,9 @@
 hestia_module_nginx_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled nginx)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'nginx' && [ ! "$param_force" ]; then
         echo "Nginx module is not installed. See 'hestia module info nginx'."
-        exit 1
+        return 1
     fi
 
     echo "Removing Nginx module..."

+ 11 - 12
bin/module/php/add.inc

@@ -4,16 +4,15 @@ hestia_module_php_add() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/php/func.inc
 
-    module_installed=$(hestia_module_isinstalled php)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'php' && [ ! "$param_force" ]; then
         echo "PHP module is not installed. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
-    module_variant=$(hestia_module_getvariant php)
+    module_variant=$(hestia_module_getvariant 'php')
     if [ "$module_variant" != 'php-fpm' ] && [ ! "$param_force" ]; then
         echo "The installed PHP module is not FPM. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     # PHP version is first parameter
@@ -21,7 +20,7 @@ hestia_module_php_add() {
 
     if [ ! "$param_ver" ]; then
         echo "You must specify PHP version"
-        exit 1
+        return 1
     fi
 
     # Verify php version format
@@ -40,21 +39,21 @@ hestia_module_php_add() {
     done
     if [ ! "$php_version" ]; then
         echo "PHP version $param_ver is not supported."
-        exit 1
+        return 1
     fi
 
-    php_withoutdot=${php_version//.}
-    php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present")
+    local php_withoutdot=${php_version//.}
+    local php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present" && echo 1)
 
     if [ "$php_version_present" ] && [ ! "$param_force" ]; then
         echo "PHP version ${php_version} is already present. See 'hestia module php list'."
-        exit 1
+        return 1
     fi
 
     # Check if php version is supported
     if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${php_withoutdot}.sh" ]; then
         echo "PHP version ${php_version} is currently not supported or does not exist."
-        exit
+        return 1
     fi
 
     # Perform verification if read-only mode is enabled
@@ -62,7 +61,7 @@ hestia_module_php_add() {
 
     echo "Adding PHP version ${php_version}..."
 
-    php_prefix=$(osal_multiphp_php_package_prefix $php_version)
+    local php_prefix=$(osal_multiphp_php_package_prefix $php_version)
 
     mph="$php_prefix-mbstring $php_prefix-bcmath $php_prefix-cli $php_prefix-curl
         $php_prefix-fpm $php_prefix-gd $php_prefix-intl $php_prefix-mysql

+ 9 - 10
bin/module/php/del.inc

@@ -4,24 +4,23 @@ hestia_module_php_del() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/php/func.inc
 
-    module_installed=$(hestia_module_isinstalled php)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'php' && [ ! "$param_force" ]; then
         echo "PHP module is not installed. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant php)
     if [ "$module_variant" != 'php-fpm' ] && [ ! "$param_force" ]; then
         echo "The installed PHP module is not FPM. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     # PHP version is first parameter
-    param_ver="$1"
+    local param_ver="$1"
 
     if [ ! $param_ver ]; then
         echo "You must specify PHP version"
-        exit 1
+        return 1
     fi
 
     # Verify php version format
@@ -40,15 +39,15 @@ hestia_module_php_del() {
     done
     if [ ! "$php_version" ]; then
         echo "PHP version $param_ver is not supported."
-        exit 1
+        return 1
     fi
 
     php_withoutdot=${php_version//.}
 
-    php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present")
+    php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present" && echo 1)
     if [ ! "$php_version_present" ] && [ ! "$param_force" ]; then
         echo "PHP version ${php_version} is not present. See 'hestia module php list'."
-        exit 1
+        return 1
     fi
 
     # Perform verification if read-only mode is enabled
@@ -91,5 +90,5 @@ hestia_module_php_del() {
 
     log_history "removed php $phpversion" '' 'admin'
 
-    exit 0
+    return 0
 }

+ 4 - 5
bin/module/php/install.inc

@@ -4,17 +4,16 @@ hestia_module_php_install() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/php/func.inc
 
-    module_installed=$(hestia_module_isinstalled php)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'php' && [ ! "$param_force" ]; then
         echo "PHP module is already installed. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     echo "Installing PHP (FPM) module..."
 
     $BIN/hestia module php add $PHP_DEFAULT_VERSION
 
-    pool_d=$(osal_multiphp_fpm_pool_d $PHP_DEFAULT_VERSION)
+    local pool_d=$(osal_multiphp_fpm_pool_d $PHP_DEFAULT_VERSION)
     mkdir -p $pool_d
     cp -f $HESTIA_INSTALL_DIR/php-fpm/www.conf $pool_d/www.conf
 
@@ -34,5 +33,5 @@ hestia_module_php_install() {
     echo "Adding default PHP version..."
     $BIN/hestia module php add $PHP_DEFAULT_VERSION
 
-    exit 0
+    return 0
 }

+ 4 - 5
bin/module/php/list.inc

@@ -4,16 +4,15 @@ hestia_module_php_list() {
     source $HESTIA/bin/module/func.inc
     source $HESTIA/bin/module/php/func.inc
 
-    module_installed=$(hestia_module_isinstalled php)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'php' && [ ! "$param_force" ]; then
         echo "PHP module is not installed. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant php)
     if [ "$module_variant" != 'php-fpm' ] && [ ! "$param_force" ]; then
         echo "The installed PHP module is not FPM. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     echo "Present PHP (FPM) versions"
@@ -23,5 +22,5 @@ hestia_module_php_list() {
         echo PHP ${php_version}: $(osal_bool_tostring $php_version_present 'present' 'not present')
     done
 
-    exit 0
+    return 0
 }

+ 3 - 3
bin/module/php/remove.inc

@@ -7,13 +7,13 @@ hestia_module_php_remove() {
     module_installed=$(hestia_module_isinstalled php)
     if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
         echo "PHP module is not installed. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant php)
     if [ "$module_variant" != 'php-fpm' ] && [ ! "$param_force" ]; then
         echo "The installed PHP module is not FPM. See 'hestia module info php'."
-        exit 1
+        return 1
     fi
 
     echo "Removing PHP (FPM) module..."
@@ -36,5 +36,5 @@ hestia_module_php_remove() {
     osal_kv_write $HESTIA_CONF_MODULES/php.conf 'variant' ''
     osal_kv_write $HESTIA_CONF_MODULES/php.conf 'version' '0'
 
-    exit 0
+    return 0
 }

+ 1 - 1
bin/module/remove.inc

@@ -7,6 +7,6 @@ hestia_module_remove() {
         $BIN/hestia module $module_name remove "$@"
     else
         echo "Usage: module install module_name"
-        exit 0
+        return 0
     fi
 }

+ 3 - 4
bin/module/spamassassin/exim-integration/disable.inc

@@ -3,16 +3,15 @@
 hestia_module_spamassassin_exim-integration_disable() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mta)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'mta' && [ ! "$param_force" ]; then
         echo "MTA module is not installed. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant mta)
     if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
         echo "The installed MTA module is not Exim. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     echo "Disabling SpamAssassin-Exim integration..."

+ 3 - 4
bin/module/spamassassin/exim-integration/enable.inc

@@ -3,16 +3,15 @@
 hestia_module_spamassassin_exim-integration_enable() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled mta)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'mta' && [ ! "$param_force" ]; then
         echo "MTA module is not installed. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant mta)
     if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
         echo "The installed MTA module is not Exim. See 'hestia module info mta'."
-        exit 1
+        return 1
     fi
 
     echo "Enabling SpamAssassin-Exim integration..."

+ 3 - 5
bin/module/spamassassin/install.inc

@@ -3,10 +3,9 @@
 hestia_module_spamassassin_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled antispam)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'antispam' && [ ! "$param_force" ]; then
         echo "Antispam module is already installed. See 'hestia module info antispam'."
-        exit 1
+        return 1
     fi
 
     echo "Installing Antispam (SpamAssassin) module..."
@@ -42,8 +41,7 @@ hestia_module_spamassassin_install() {
     osal_kv_write $HESTIA_CONF_MODULES/antispam.conf 'version' '1'
     osal_kv_write $HESTIA_CONF_MODULES/antispam.conf 'service_name' $OSAL_SERVICE_SPAMASSASSIN
 
-    exim_installed=$(hestia_module_variant_installed 'mta' 'exim')
-    if [ "$exim_installed" ]; then
+    if hestia_module_variant_installed 'mta' 'exim'; then
         $BIN/hestia module spamassassin exim-integration enable
     fi
 }

+ 5 - 7
bin/module/spamassassin/remove.inc

@@ -3,22 +3,20 @@
 hestia_module_spamassassin_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled antispam)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'antispam' && [ ! "$param_force" ]; then
         echo "Antispam module is not installed. See 'hestia module info antispam'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant antispam)
     if [ "$module_variant" != 'spamassassin' ] && [ ! "$param_force" ]; then
         echo "The installed antispam module is not SpamAssassin. See 'hestia module info antispam'."
-        exit 1
+        return 1
     fi
 
     echo "Removing antispam (SpamAssassin) module..."
 
-    exim_installed=$(hestia_module_variant_installed 'mta' 'exim')
-    if [ "$exim_installed" ]; then
+    if hestia_module_variant_installed 'mta' 'exim'; then
         $BIN/hestia module spamassassin exim-integration disable
     fi
 
@@ -38,5 +36,5 @@ hestia_module_spamassassin_remove() {
     osal_kv_write $HESTIA_CONF_MODULES/antispam.conf 'variant' ''
     osal_kv_write $HESTIA_CONF_MODULES/antispam.conf 'version' '0'
 
-    exit 0
+    return 0
 }

+ 3 - 4
bin/module/vsftpd/install.inc

@@ -3,10 +3,9 @@
 hestia_module_vsftpd_install() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled ftp)
-    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+    if hestia_module_isinstalled 'ftp' && [ ! "$param_force" ]; then
         echo "FTP module is already installed. See 'hestia module info ftp'."
-        exit 1
+        return 1
     fi
 
     echo "Installing FTP (vsftpd) module..."
@@ -37,5 +36,5 @@ hestia_module_vsftpd_install() {
     osal_kv_write $HESTIA_CONF_MODULES/ftp.conf 'version' '1'
     osal_kv_write $HESTIA_CONF_MODULES/ftp.conf 'service_name' 'vsftpd'
 
-    exit 0
+    return 0
 }

+ 4 - 5
bin/module/vsftpd/remove.inc

@@ -3,16 +3,15 @@
 hestia_module_vsftpd_remove() {
     source $HESTIA/bin/module/func.inc
 
-    module_installed=$(hestia_module_isinstalled ftp)
-    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+    if ! hestia_module_isinstalled 'ftp' && [ ! "$param_force" ]; then
         echo "FTP module is not installed. See 'hestia module info ftp'."
-        exit 1
+        return 1
     fi
 
     module_variant=$(hestia_module_getvariant ftp)
     if [ "$module_variant" != 'vsftpd' ] && [ ! "$param_force" ]; then
         echo "The installed FTP module is not vsftpd. See 'hestia module info ftp'."
-        exit 1
+        return 1
     fi
 
     echo "Removing FTP (vsftpd) module..."
@@ -33,5 +32,5 @@ hestia_module_vsftpd_remove() {
     osal_kv_write $HESTIA_CONF_MODULES/ftp.conf 'variant' ''
     osal_kv_write $HESTIA_CONF_MODULES/ftp.conf 'version' '0'
 
-    exit 0
+    return 0
 }

+ 3 - 4
bin/module/web/setup.inc

@@ -3,8 +3,8 @@
 hestia_module_web_setup() {
     source $HESTIA/bin/module/func.inc
 
-    apache_installed=$(hestia_module_isinstalled apache)
-    nginx_installed=$(hestia_module_isinstalled nginx)
+    local apache_installed=$(hestia_module_isinstalled apache && echo 1)
+    local nginx_installed=$(hestia_module_isinstalled nginx && echo 1)
 
     if [ "$apache_installed" ] && [ ! "$nginx_installed" ] ; then
         echo "Setup Web module (Apache only)..."
@@ -76,10 +76,9 @@ hestia_module_web_setup() {
 
     if [ "$apache_installed" ] || [ "$nginx_installed" ] ; then
         $BIN/hestia module web setup-ips
-
         # FIXME: setup PHP support
-        php_variant=$(hestia_module_variant_installed php)
         if [ "$apache_installed" ]; then
+            local php_variant=$(hestia_module_variant_installed 'php')
             # Enable mod_ruid/mpm_itk or mpm_event
             if [ "$php_variant" = 'php-fpm' ]; then
                 # Disable prefork and php, enable event

+ 1 - 1
bin/package/install/mail-server.inc

@@ -5,7 +5,7 @@ hestia_package_install_mail-server() {
 
     if [ "$param_help" ]; then
         usage
-        exit 0
+        return 0
     fi
 
     echo "Installing mail server package..."

+ 1 - 1
bin/package/install/web-server.inc

@@ -5,7 +5,7 @@ hestia_package_install_mail-server() {
 
     if [ "$param_help" ]; then
         usage
-        exit 0
+        return 0
     fi
 
     echo "Installing web server package..."

+ 15 - 11
func/osal.sh

@@ -40,7 +40,7 @@ done
 # VAR=$(ini_get 'file' 'section' 'param' 'value')
 osal_ini_get() {
     #echo /usr/bin/crudini --get $@
-    retval=$(/usr/bin/crudini --get $@ 2>1)
+    local retval=$(/usr/bin/crudini --get $@ 2>1)
     if [ $? -eq 0 ]; then
         echo $retval
     fi
@@ -67,9 +67,9 @@ osal_kv_write() {
 
 # value=$(osal_kv_read path key defaultvalue)
 osal_kv_read() {
-    kv_keyname=$(echo "$2" | sed_escape)
+    local kv_keyname=$(echo "$2" | sed_escape)
     if [ -f "$1" ]; then
-        retval=$(grep "^$kv_keyname\s*=" "$1" | sed "s/^$kv_keyname\s*=\s*//" | tail -1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
+        local retval=$(grep "^$kv_keyname\s*=" "$1" | sed "s/^$kv_keyname\s*=\s*//" | tail -1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
         if [ "$retval" ]; then
             echo $retval
         else
@@ -81,25 +81,29 @@ osal_kv_read() {
 }
 
 osal_kv_delete() { # path, key
-    kv_keyname=$(echo "$2" | sed_escape)
+    local kv_keyname=$(echo "$2" | sed_escape)
     test -f "$1" && sed -i "/^${kv_keyname}\s*=.*$/d" "$1"
 }
 
 osal_kv_haskey() { # path, key
-    kv_keyname=$(echo "$2" | sed_escape)
+    local kv_keyname=$(echo "$2" | sed_escape)
     test -f "$1" && grep "^${kv_keyname}\s*=" "$1" > /dev/null
     if [ $? -eq 0 ]; then
-        echo 1
+        return 0
+    else
+        return 1
     fi
 }
 
 osal_kv_read_bool() {
-    retval=$(osal_kv_read $@)
+    local retval=$(osal_kv_read $@)
     if [ "${retval,,}" == "yes" ] \
         || [ "${retval,,}" == "true" ] \
         || [ "${retval,,}" == "on" ] \
         || [ "$retval" == "1" ]; then
-        echo 1
+        return 0
+    else
+        return 1
     fi
 }
 
@@ -121,10 +125,10 @@ osal_execute_with_spinner() {
         $@
     else
         $@ > /dev/null 2>&1 &
-        BACK_PID=$!
+        local BACK_PID=$!
 
-        spinner="/-\|"
-        spin_i=1
+        local spinner="/-\|"
+        local spin_i=1
         while kill -0 $BACK_PID > /dev/null 2>&1 ; do
             printf "\b${spinner:spin_i++%${#spinner}:1}"
             sleep 0.5