config 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. source _ynh_add_fpm_config
  10. #=================================================
  11. # RETRIEVE ARGUMENTS
  12. #=================================================
  13. app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
  14. #=================================================
  15. # SPECIFIC CODE
  16. #=================================================
  17. # LOAD VALUES
  18. #=================================================
  19. # Load the real value from the app config or elsewhere.
  20. # Then get the value from the form.
  21. # If the form has a value for a variable, take the value from the form,
  22. # Otherwise, keep the value from the app config.
  23. # Overwrite setupVars.conf file
  24. old_overwrite_setupvars="$(ynh_app_setting_get --app=$app --key=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=$app --key=overwrite_ftl)"
  28. overwrite_ftl="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL:-$old_overwrite_ftl}"
  29. # Overwrite nginx configuration
  30. old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
  31. overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
  32. # Overwrite php-fpm configuration
  33. old_overwrite_phpfpm="$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)"
  34. overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
  35. # Type of admin mail configuration
  36. old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)"
  37. admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
  38. # Footprint for php-fpm
  39. old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)"
  40. fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}"
  41. # Free footprint value for php-fpm
  42. # Check if fpm_footprint is an integer
  43. if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null
  44. then
  45. # If fpm_footprint is an integer, that's a numeric value for the footprint
  46. old_free_footprint=$fpm_footprint
  47. fpm_footprint=specific
  48. else
  49. old_free_footprint=0
  50. fi
  51. free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}"
  52. # Usage for php-fpm
  53. old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)"
  54. fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}"
  55. #=================================================
  56. # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
  57. #=================================================
  58. show_config() {
  59. # here you are supposed to read some config file/database/other then print the values
  60. # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
  61. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
  62. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
  63. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
  64. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
  65. ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
  66. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint"
  67. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint"
  68. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage"
  69. }
  70. #=================================================
  71. # MODIFY THE CONFIGURATION
  72. #=================================================
  73. apply_config() {
  74. #=================================================
  75. # MODIFY OVERWRITTING SETTINGS
  76. #=================================================
  77. # Set overwrite_setupvars
  78. ynh_app_setting_set --app=$app --key=overwrite_setupvars --value="$overwrite_setupvars"
  79. # Set overwrite_ftl
  80. ynh_app_setting_set --app=$app --key=overwrite_ftl --value="$overwrite_ftl"
  81. # Set overwrite_nginx
  82. ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
  83. # Set overwrite_phpfpm
  84. ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="$overwrite_phpfpm"
  85. #=================================================
  86. # MODIFY EMAIL SETTING
  87. #=================================================
  88. # Set admin_mail_html
  89. ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
  90. #=================================================
  91. # RECONFIGURE PHP-FPM
  92. #=================================================
  93. if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ] || [ "$free_footprint" != "$old_free_footprint" ]
  94. then
  95. # If fpm_footprint is set to 'specific', use $free_footprint value.
  96. if [ "$fpm_footprint" = "specific" ]
  97. then
  98. fpm_footprint=$free_footprint
  99. fi
  100. if [ "$fpm_footprint" != "0" ]
  101. then
  102. ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
  103. else
  104. ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
  105. fi
  106. fi
  107. }
  108. #=================================================
  109. # GENERIC FINALIZATION
  110. #=================================================
  111. # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
  112. #=================================================
  113. case $1 in
  114. show) show_config;;
  115. apply) apply_config;;
  116. esac