func.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. HESTIA_CONF_MODULES=$HESTIA/conf/modules
  3. mkdir -p $HESTIA_CONF_MODULES
  4. # Tests if module is installed, exits successfully if it does.
  5. hestia_module_isinstalled() {
  6. osal_kv_read_bool $HESTIA_CONF_MODULES/${1}.conf 'installed'
  7. }
  8. # Returns a module version
  9. hestia_module_getversion() {
  10. osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'version'
  11. }
  12. # Returns module installed variant
  13. hestia_module_getvariant() {
  14. osal_kv_read $HESTIA_CONF_MODULES/${1}.conf 'variant'
  15. }
  16. # Tests if a specific variant of a module is installed,
  17. # exits successfully if it does.
  18. hestia_module_variant_installed() {
  19. local module_installed=$(hestia_module_isinstalled $1 && echo 1)
  20. if [ "$module_installed" ]; then
  21. local module_variant=$(hestia_module_getvariant $1)
  22. if [ "$module_variant" = "$2" ]; then
  23. return 0
  24. fi
  25. fi
  26. return 1
  27. }
  28. # Schedules a service restart (when doing multiple actions)
  29. hestia_module_service_restart_schedule() {
  30. if [ ! "$hestia_module_service_restart_list" ]; then
  31. hestia_module_service_restart_list=$1
  32. else
  33. # FIXME: don't add services twice
  34. hestia_module_service_restart_list="hestia_module_service_restart_list $1"
  35. fi
  36. }
  37. # Restart services scheduled for restart
  38. hestia_module_service_restart_restart() {
  39. if [ ! "$hestia_module_service_restart_list" ]; then
  40. for svc in $hestia_module_service_restart_list; do
  41. osal_service_restart $svc
  42. done
  43. fi
  44. }
  45. # Backup config files (usually prior to module install)
  46. # hestia_config_backup 'prefix' file1 file2 file3 ...
  47. hestia_config_backup() {
  48. local dest=$HESTIA/data/backup/
  49. local filename=${1}-$(date +%Y%m%d%H%M%S)
  50. shift
  51. mkdir -p $dest
  52. [ "$HESTIA_DEBUG" ] && >&2 echo tarring -f $dest/${filename}.tar.gz $@
  53. tar -zc --ignore-failed-read -f $dest/${filename}.tar.gz $@ > /dev/null 2>&1
  54. }
  55. hestia_safe_rm() {
  56. for file in "$@"; do
  57. if [[ $file =~ ^/etc/.*|^/var/.* ]]; then
  58. [ "$HESTIA_DEBUG" ] && >&2 echo rm -rf $file
  59. rm -rf $file
  60. fi
  61. done
  62. }