func.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if hestia_module_isinstalled $1; then
  20. local module_variant=$(hestia_module_getvariant $1)
  21. echo $module_variant
  22. fi
  23. }
  24. # Schedules a service restart (when doing multiple actions)
  25. hestia_module_service_restart_schedule() {
  26. if [ ! "$hestia_module_service_restart_list" ]; then
  27. hestia_module_service_restart_list=$1
  28. else
  29. # FIXME: don't add services twice
  30. hestia_module_service_restart_list="hestia_module_service_restart_list $1"
  31. fi
  32. }
  33. # Restart services scheduled for restart
  34. hestia_module_service_restart_restart() {
  35. if [ ! "$hestia_module_service_restart_list" ]; then
  36. for svc in $hestia_module_service_restart_list; do
  37. osal_service_restart $svc
  38. done
  39. fi
  40. }
  41. # Backup config files (usually prior to module install)
  42. # hestia_config_backup 'prefix' file1 file2 file3 ...
  43. hestia_config_backup() {
  44. local dest=$HESTIA/data/backup/
  45. local filename=${1}-$(date +%Y%m%d%H%M%S)
  46. shift
  47. if [ "$1" ]; then
  48. mkdir -p $dest
  49. [ "$HESTIA_DEBUG" ] && >&2 echo tarring -f $dest/${filename}.tar.gz $@
  50. tar -zc --ignore-failed-read -f $dest/${filename}.tar.gz $@ > /dev/null 2>&1
  51. fi
  52. }
  53. hestia_safe_rm() {
  54. for file in "$@"; do
  55. if [[ $file =~ ^/etc/.*|^/var/.*|^/usr/share/.* ]]; then
  56. [ "$HESTIA_DEBUG" ] && >&2 echo rm -rf $file
  57. rm -rf $file
  58. fi
  59. done
  60. }