config 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 overwrite_setupvars)"
  25. old_overwrite_setupvars=$(bool_to_true_false $old_overwrite_setupvars)
  26. overwrite_setupvars="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS:-$old_overwrite_setupvars}"
  27. # Overwrite pihole-FTL.conf file
  28. old_overwrite_ftl="$(ynh_app_setting_get $app overwrite_ftl)"
  29. old_overwrite_ftl=$(bool_to_true_false $old_overwrite_ftl)
  30. overwrite_ftl="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL:-$old_overwrite_ftl}"
  31. # Overwrite nginx configuration
  32. old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)"
  33. old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
  34. overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
  35. # Overwrite php-fpm configuration
  36. old_overwrite_phpfpm="$(ynh_app_setting_get $app overwrite_phpfpm)"
  37. old_overwrite_phpfpm=$(bool_to_true_false $old_overwrite_phpfpm)
  38. overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
  39. # Type of admin mail configuration
  40. old_admin_mail_html="$(ynh_app_setting_get $app admin_mail_html)"
  41. old_admin_mail_html=$(bool_to_true_false $old_admin_mail_html)
  42. admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
  43. # Footprint for php-fpm
  44. old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)"
  45. fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}"
  46. # Free footprint value for php-fpm
  47. # Check if fpm_footprint is an integer
  48. if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null
  49. then
  50. # If fpm_footprint is an integer, that's a numeric value for the footprint
  51. old_free_footprint=$fpm_footprint
  52. fpm_footprint=specific
  53. else
  54. old_free_footprint=0
  55. fi
  56. free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}"
  57. # Usage for php-fpm
  58. old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)"
  59. fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}"
  60. #=================================================
  61. # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
  62. #=================================================
  63. show_config() {
  64. # here you are supposed to read some config file/database/other then print the values
  65. # echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
  66. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
  67. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
  68. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
  69. echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
  70. echo "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
  71. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint"
  72. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint"
  73. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage"
  74. }
  75. #=================================================
  76. # MODIFY THE CONFIGURATION
  77. #=================================================
  78. apply_config() {
  79. # Set overwrite_setupvars
  80. overwrite_setupvars=$(bool_to_01 $overwrite_setupvars)
  81. ynh_app_setting_set $app overwrite_setupvars "$overwrite_setupvars"
  82. # Set overwrite_ftl
  83. overwrite_ftl=$(bool_to_01 $overwrite_ftl)
  84. ynh_app_setting_set $app overwrite_ftl "$overwrite_ftl"
  85. # Set overwrite_nginx
  86. overwrite_nginx=$(bool_to_01 $overwrite_nginx)
  87. ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx"
  88. # Set overwrite_phpfpm
  89. overwrite_phpfpm=$(bool_to_01 $overwrite_phpfpm)
  90. ynh_app_setting_set $app overwrite_phpfpm "$overwrite_phpfpm"
  91. # Set admin_mail_html
  92. admin_mail_html=$(bool_to_01 $admin_mail_html)
  93. ynh_app_setting_set $app admin_mail_html "$admin_mail_html"
  94. #=================================================
  95. # RECONFIGURE PHP-FPM
  96. #=================================================
  97. if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ] || [ "$free_footprint" != "$old_free_footprint" ]
  98. then
  99. # If fpm_footprint is set to 'specific', use $free_footprint value.
  100. if [ "$fpm_footprint" = "specific" ]
  101. then
  102. fpm_footprint=$free_footprint
  103. fi
  104. if [ "$fpm_footprint" != "0" ]
  105. then
  106. ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
  107. else
  108. ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
  109. fi
  110. fi
  111. }
  112. #=================================================
  113. # GENERIC FINALIZATION
  114. #=================================================
  115. # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
  116. #=================================================
  117. case $1 in
  118. show) show_config;;
  119. apply) apply_config;;
  120. esac