From b5c21f0c3d981eeacaa690c01147ba9e7ad17478 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Wed, 8 Dec 2021 15:17:53 +0100 Subject: [PATCH] Upgrade config panel --- config_panel.toml | 4 +- scripts/_common.sh | 1 + scripts/config | 117 +++++++++++++++++++++++---------------------- 3 files changed, 63 insertions(+), 59 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index acc6ffb..dc5ced4 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -6,7 +6,7 @@ name = "Nextcloud configuration" [main.php_fpm_config] name = "PHP-FPM configuration" - [main.php_fpm_config.footprint] + [main.php_fpm_config.fpm_footprint] ask = "Memory footprint of the service?" choices = ["low", "medium", "high", "specific"] default = "low" @@ -18,7 +18,7 @@ name = "Nextcloud configuration" default = "0" help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." - [main.php_fpm_config.usage] + [main.php_fpm_config.fpm_usage] ask = "Expected usage of the service?" choices = ["low", "medium", "high"] default = "low" diff --git a/scripts/_common.sh b/scripts/_common.sh index 50e6812..ce10116 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,3 +1,4 @@ +#!/bin/bash #================================================= # COMMON VARIABLES diff --git a/scripts/config b/scripts/config index 221cbf1..3440bd2 100644 --- a/scripts/config +++ b/scripts/config @@ -9,84 +9,87 @@ source _common.sh source /usr/share/yunohost/helpers +ynh_abort_if_errors + #================================================= # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_INSTANCE_NAME - phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) #================================================= -# LOAD VALUES +# SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= -# Load the real value from the app config or elsewhere. -# Then get the value from the form. -# If the form has a value for a variable, take the value from the form, -# Otherwise, keep the value from the app config. +get__fpm_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + echo "specific" + else + echo "$current_fpm_footprint" + fi +} -# Footprint for php-fpm -old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)" -fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}" - -# Free footprint value for php-fpm -# Check if fpm_footprint is an integer -if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null -then - # If fpm_footprint is an integer, that's a numeric value for the footprint - old_free_footprint=$fpm_footprint - fpm_footprint=specific -else - old_free_footprint=0 -fi -free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}" - -# Usage for php-fpm -old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)" -fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}" - -#================================================= -# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND -#================================================= - -show_config() { - # here you are supposed to read some config file/database/other then print the values - # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" - - ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint" - ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint" - ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage" +get__free_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + # If current_fpm_footprint is an integer, that's a numeric value for the footprint + echo "$current_fpm_footprint" + else + echo "0" + fi } #================================================= -# MODIFY THE CONFIGURATION +# SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= -apply_config() { - - #================================================= - # RECONFIGURE PHP-FPM - #================================================= - - if [ "$fpm_usage" != "$old_fpm_usage" ] || [ "$fpm_footprint" != "$old_fpm_footprint" ] || [ "$free_footprint" != "$old_free_footprint" ] +set__fpm_footprint() { + if [ "$fpm_footprint" != "specific" ] then - # If fpm_footprint is set to 'specific', use $free_footprint value. - if [ "$fpm_footprint" = "specific" ] - then - fpm_footprint=$free_footprint - fi + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" + fi +} - if [ "$fpm_footprint" != "0" ] - then - ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint --package="$extra_php_dependencies" - else - ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." - fi +set__free_footprint() { + if [ "$fpm_footprint" = "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$free_footprint" fi } #================================================= # GENERIC FINALIZATION #================================================= + +ynh_app_config_validate() { + _ynh_app_config_validate + + if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then + # If fpm_footprint is set to 'specific', use $free_footprint value. + if [ "$fpm_footprint" = "specific" ] + then + fpm_footprint=$free_footprint + fi + + if [ "$fpm_footprint" == "0" ] + then + ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." + + exit 0 + fi + fi +} + +ynh_app_config_apply() { + _ynh_app_config_apply + + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint +} + ynh_app_config_run $1