func.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. tar -zc --warning=none --ignore-failed-read -f $dest/${filename}.tar.gz $@ > /dev/null 2>&1
  53. }