config 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # RETRIEVE ARGUMENTS
  11. #=================================================
  12. app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
  13. #=================================================
  14. # SPECIFIC CODE
  15. #=================================================
  16. # LOAD VALUES
  17. #=================================================
  18. # Load the real value from the app config or elsewhere.
  19. # Then get the value from the form.
  20. # If the form has a value for a variable, take the value from the form,
  21. # Otherwise, keep the value from the app config.
  22. # Overwrite setupVars.conf file
  23. old_overwrite_setupvars="$(ynh_app_setting_get $app overwrite_setupvars)"
  24. old_overwrite_setupvars=$(bool_to_true_false $old_overwrite_setupvars)
  25. overwrite_setupvars="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS:-$old_overwrite_setupvars}"
  26. # Overwrite pihole-FTL.conf file
  27. old_overwrite_ftl="$(ynh_app_setting_get $app overwrite_ftl)"
  28. old_overwrite_ftl=$(bool_to_true_false $old_overwrite_ftl)
  29. overwrite_ftl="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL:-$old_overwrite_ftl}"
  30. # Overwrite nginx configuration
  31. old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)"
  32. old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
  33. overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
  34. # Overwrite php-fpm configuration
  35. old_overwrite_phpfpm="$(ynh_app_setting_get $app overwrite_phpfpm)"
  36. old_overwrite_phpfpm=$(bool_to_true_false $old_overwrite_phpfpm)
  37. overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
  38. # Type of admin mail configuration
  39. old_admin_mail_html="$(ynh_app_setting_get $app admin_mail_html)"
  40. old_admin_mail_html=$(bool_to_true_false $old_admin_mail_html)
  41. admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
  42. #=================================================
  43. # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
  44. #=================================================
  45. show_config() {
  46. # here you are supposed to read some config file/database/other then print the values
  47. # echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
  48. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
  49. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
  50. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
  51. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
  52. echo "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
  53. }
  54. #=================================================
  55. # MODIFY THE CONFIGURATION
  56. #=================================================
  57. apply_config() {
  58. # Set overwrite_setupvars
  59. overwrite_setupvars=$(bool_to_01 $overwrite_setupvars)
  60. ynh_app_setting_set $app overwrite_setupvars "$overwrite_setupvars"
  61. # Set overwrite_ftl
  62. overwrite_ftl=$(bool_to_01 $overwrite_ftl)
  63. ynh_app_setting_set $app overwrite_ftl "$overwrite_ftl"
  64. # Set overwrite_nginx
  65. overwrite_nginx=$(bool_to_01 $overwrite_nginx)
  66. ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx"
  67. # Set overwrite_phpfpm
  68. overwrite_phpfpm=$(bool_to_01 $overwrite_phpfpm)
  69. ynh_app_setting_set $app overwrite_phpfpm "$overwrite_phpfpm"
  70. # Set admin_mail_html
  71. admin_mail_html=$(bool_to_01 $admin_mail_html)
  72. ynh_app_setting_set $app admin_mail_html "$admin_mail_html"
  73. }
  74. #=================================================
  75. # GENERIC FINALIZATION
  76. #=================================================
  77. # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
  78. #=================================================
  79. case $1 in
  80. show) show_config;;
  81. apply) apply_config;;
  82. esac