install.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. hestia_module_install() {
  3. source $HESTIA/bin/module/func.inc
  4. if [ "$1" ]; then
  5. local mod_name=$1
  6. shift
  7. local mod_provider=$(hestia module what-provides $mod_name)
  8. if [ "$mod_provider" != "$mod_name" ]; then
  9. echo "Module '${mod_provider}' selected as provider of '${mod_name}'"
  10. fi
  11. local hmd="$HESTIA/data/modules/${mod_provider}.hmd"
  12. local mod_conflicts=$(osal_kv_read $hmd 'conflicts')
  13. if [ "$mod_conflicts" ] && ! hestia_module_install_check_conflicts "$mod_provider" "$mod_conflicts"; then
  14. return 1
  15. fi
  16. local mod_requires=$(osal_kv_read $hmd 'requires')
  17. if [ "$mod_requires" ] && ! hestia_module_install_check_requires "$mod_provider" "$mod_requires"; then
  18. return 1
  19. fi
  20. if ! hestia module "$mod_provider" install "$@"; then
  21. echo "$mod_provider module installation failed"
  22. fi
  23. # Write installed module info
  24. osal_kv_write $HESTIA_CONF_MODULES/$mod_provider.conf 'installed' '1'
  25. osal_kv_write $HESTIA_CONF_MODULES/$mod_provider.conf 'hmd' "$hmd"
  26. osal_kv_write $HESTIA_CONF_MODULES/$mod_provider.conf 'isprovider' "$hmd"
  27. local mod_provides=$(osal_kv_read $hmd 'provides')
  28. if [ "$mod_provides" ]; then
  29. # Write what this module provides
  30. for mod in $mod_provides; do
  31. local current_variant=$(hestia_module_variant_installed $mod)
  32. current_variant="$mod_provider $current_variant"
  33. osal_kv_write $HESTIA_CONF_MODULES/$mod.conf 'installed' 1
  34. osal_kv_write $HESTIA_CONF_MODULES/$mod.conf $mod_provider 'yes'
  35. osal_kv_write $HESTIA_CONF_MODULES/$mod.conf 'variant' $current_variant
  36. done
  37. fi
  38. if [ ! "$param_nointegrate" ]; then
  39. # Now integrate everything we've just installed
  40. for mod in $mod_provider $mod_requires; do
  41. hestia module $mod integrate
  42. done
  43. fi
  44. else
  45. echo "Usage: module install module_name"
  46. return 1
  47. fi
  48. }
  49. # Check whether conflicting modules are installed,
  50. # returns 1 if a conflict is found.
  51. hestia_module_install_check_conflicts() {
  52. local mod_name=$1
  53. shift
  54. for mod in "$@"; do
  55. if hestia_module_isinstalled $mod; then
  56. echo "'$mod_name' conflicts with an installed module. Please remove '$mod' first."
  57. return 1
  58. fi
  59. done
  60. return 0
  61. }
  62. # Check whether required modules are installed and installs
  63. # them if necessary, returns 1 if a requirements can't be installed.
  64. hestia_module_install_check_requires() {
  65. local mod_name=$1
  66. shift
  67. for mod in $@; do
  68. [ "$HESTIA_DEBUG" ] && echo "Check dependency: $mod"
  69. if ! hestia_module_isinstalled $mod; then
  70. if ! hestia module install $mod --nointegrate; then
  71. echo "Module '${mod}' is required for module '${mod_name}' but can not be installed"
  72. return 1
  73. fi
  74. fi
  75. done
  76. return 0
  77. }