Ernesto Nicolás Carrea 5 лет назад
Родитель
Сommit
ee024a809c
2 измененных файлов с 15 добавлено и 5 удалено
  1. 4 3
      bin/module/func.inc
  2. 11 2
      func/osal.sh

+ 4 - 3
bin/module/func.inc

@@ -3,12 +3,12 @@
 HESTIA_CONF_MODULES=$HESTIA/conf/modules
 HESTIA_CONF_MODULES=$HESTIA/conf/modules
 mkdir -p $HESTIA_CONF_MODULES
 mkdir -p $HESTIA_CONF_MODULES
 
 
-# Tests if module is installed
+# Tests if module is installed, exits successfully if it does.
 hestia_module_isinstalled() {
 hestia_module_isinstalled() {
     osal_kv_read_bool $HESTIA_CONF_MODULES/${1}.conf 'installed'
     osal_kv_read_bool $HESTIA_CONF_MODULES/${1}.conf 'installed'
 }
 }
 
 
-# Returns module version
+# Returns a module version
 hestia_module_getversion() {
 hestia_module_getversion() {
     osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'version'
     osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'version'
 }
 }
@@ -18,7 +18,8 @@ hestia_module_getvariant() {
     osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'variant'
     osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'variant'
 }
 }
 
 
-# Tests if a specific variant of a module is installed
+# Tests if a specific variant of a module is installed,
+# exits successfully if it does.
 hestia_module_variant_installed() {
 hestia_module_variant_installed() {
     local module_installed=$(hestia_module_isinstalled $1 && echo 1)
     local module_installed=$(hestia_module_isinstalled $1 && echo 1)
     if [ "$module_installed" ]; then
     if [ "$module_installed" ]; then

+ 11 - 2
func/osal.sh

@@ -59,13 +59,15 @@ sed_escape() {
     sed -e 's/[]\/$*.^[]/\\&/g'
     sed -e 's/[]\/$*.^[]/\\&/g'
 }
 }
 
 
-# osal_kv_write path key value
+# Writes a value to a key-value file.
+# osal_kv_write 'path' 'key' 'value'
 osal_kv_write() { 
 osal_kv_write() { 
     osal_kv_delete "$1" "$2"
     osal_kv_delete "$1" "$2"
     echo "$2=$3" >> "$1"
     echo "$2=$3" >> "$1"
 }
 }
 
 
-# value=$(osal_kv_read path key defaultvalue)
+# Reads a value from a key-value file.
+# Exits successfully if it does.# value=$(osal_kv_read path key defaultvalue)
 osal_kv_read() {
 osal_kv_read() {
     local kv_keyname=$(echo "$2" | sed_escape)
     local kv_keyname=$(echo "$2" | sed_escape)
     if [ -f "$1" ]; then
     if [ -f "$1" ]; then
@@ -80,11 +82,14 @@ osal_kv_read() {
     fi
     fi
 }
 }
 
 
+# Deletes a value in a key-value file.
 osal_kv_delete() { # path, key
 osal_kv_delete() { # path, key
     local kv_keyname=$(echo "$2" | sed_escape)
     local kv_keyname=$(echo "$2" | sed_escape)
     test -f "$1" && sed -i "/^${kv_keyname}\s*=.*$/d" "$1"
     test -f "$1" && sed -i "/^${kv_keyname}\s*=.*$/d" "$1"
 }
 }
 
 
+# Tests if a value exists in a key-value file.
+# Exits successfully if it does.
 osal_kv_haskey() { # path, key
 osal_kv_haskey() { # path, key
     local kv_keyname=$(echo "$2" | sed_escape)
     local kv_keyname=$(echo "$2" | sed_escape)
     test -f "$1" && grep "^${kv_keyname}\s*=" "$1" > /dev/null
     test -f "$1" && grep "^${kv_keyname}\s*=" "$1" > /dev/null
@@ -95,6 +100,8 @@ osal_kv_haskey() { # path, key
     fi
     fi
 }
 }
 
 
+# Tests if a boolean value is true in a key-value file.
+# Exits successfully if it does.
 osal_kv_read_bool() {
 osal_kv_read_bool() {
     local retval=$(osal_kv_read $@)
     local retval=$(osal_kv_read $@)
     if [ "${retval,,}" == "yes" ] \
     if [ "${retval,,}" == "yes" ] \
@@ -107,6 +114,7 @@ osal_kv_read_bool() {
     fi
     fi
 }
 }
 
 
+# Converts a boolean value to 'yes'/'no' (or two terms provided as second and third argument)
 # answer=$(osal_bool_tostring boolean_value yes_value no_value)
 # answer=$(osal_bool_tostring boolean_value yes_value no_value)
 osal_bool_tostring() {
 osal_bool_tostring() {
     if [ "${1,,}" == "yes" ] \
     if [ "${1,,}" == "yes" ] \
@@ -119,6 +127,7 @@ osal_bool_tostring() {
     fi
     fi
 }
 }
 
 
+# Executes a process silently in the background while showing a spinner
 osal_execute_with_spinner() {
 osal_execute_with_spinner() {
     if [ "$OSAL_DEBUG" ]; then
     if [ "$OSAL_DEBUG" ]; then
         echo "$@"
         echo "$@"