install.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_INSTALL_DIR/../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. if [ ! "$param_force" ]; then
  23. exit 1
  24. fi
  25. fi
  26. # Write installed module info
  27. osal_kv_write $HESTIA_CONF_MODULES/$mod_provider.conf 'installed' '1'
  28. osal_kv_write $HESTIA_CONF_MODULES/$mod_provider.conf 'hmd' "$hmd"
  29. osal_kv_write $HESTIA_CONF_MODULES/$mod_provider.conf 'isprovider' "$hmd"
  30. local mod_provides=$(osal_kv_read $hmd 'provides')
  31. if [ "$mod_provides" ]; then
  32. # Write what this module provides
  33. for mod in $mod_provides; do
  34. local current_variant=$(hestia_module_variant_installed $mod)
  35. current_variant="$mod_provider $current_variant"
  36. osal_kv_write $HESTIA_CONF_MODULES/$mod.conf 'installed' 1
  37. osal_kv_write $HESTIA_CONF_MODULES/$mod.conf $mod_provider 'yes'
  38. osal_kv_write $HESTIA_CONF_MODULES/$mod.conf 'variant' $current_variant
  39. done
  40. fi
  41. if [ ! "$param_no_integrate" ]; then
  42. # Now integrate everything we've just installed
  43. for mod in $mod_provider $mod_requires; do
  44. hestia module $mod integrate
  45. done
  46. fi
  47. else
  48. echo "Usage: module install module_name"
  49. return 1
  50. fi
  51. }
  52. # Check whether conflicting modules are installed,
  53. # returns 1 if a conflict is found.
  54. hestia_module_install_check_conflicts() {
  55. local mod_name=$1
  56. shift
  57. for mod in "$@"; do
  58. if hestia_module_isinstalled $mod; then
  59. echo "'$mod_name' conflicts with an installed module. Please remove '$mod' first."
  60. return 1
  61. fi
  62. done
  63. return 0
  64. }
  65. # Check whether required modules are installed and installs
  66. # them if necessary, returns 1 if a requirements can't be installed.
  67. hestia_module_install_check_requires() {
  68. local mod_name=$1
  69. shift
  70. for mod in $@; do
  71. [ "$HESTIA_DEBUG" ] && echo "Check dependency: $mod"
  72. if ! hestia_module_isinstalled $mod; then
  73. if ! hestia module install $mod --no-integrate; then
  74. echo "Module '${mod}' is required for module '${mod_name}' but can not be installed"
  75. return 1
  76. fi
  77. fi
  78. done
  79. return 0
  80. }