2020-11-03 23:28:45 +03:00
|
|
|
#!/bin/bash
|
2021-09-29 03:41:30 +03:00
|
|
|
# In simple cases, you don't need a config script.
|
2020-11-03 23:48:58 +03:00
|
|
|
|
|
|
|
# With a simple config_panel.toml, you can write in the app settings, in the
|
2021-09-29 03:41:30 +03:00
|
|
|
# upstream config file or replace complete files (logo ...) and restart services.
|
2020-11-03 23:48:58 +03:00
|
|
|
|
|
|
|
# The config scripts allows you to go further, to handle specific cases
|
|
|
|
# (validation of several interdependent fields, specific getter/setter for a value,
|
2021-09-29 03:41:30 +03:00
|
|
|
# display dynamic informations or choices, pre-loading of config type .cube... ).
|
2020-11-03 23:28:45 +03:00
|
|
|
|
2021-09-29 03:41:30 +03:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2020-11-03 23:28:45 +03:00
|
|
|
|
2021-09-29 03:41:30 +03:00
|
|
|
source /usr/share/yunohost/helpers
|
2020-11-03 23:28:45 +03:00
|
|
|
|
2021-09-29 03:41:30 +03:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-07 12:16:26 +03:00
|
|
|
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
2020-11-03 23:28:45 +03:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
|
|
|
#=================================================
|
2021-09-29 03:41:30 +03:00
|
|
|
|
|
|
|
get__amount() {
|
|
|
|
# Here we can imagine to have an API call to stripe to know the amount of donation during a month
|
|
|
|
local amount = 200
|
|
|
|
|
|
|
|
# It's possible to change some properties of the question by overriding it:
|
|
|
|
if [ $amount -gt 100 ]
|
2020-11-03 23:28:45 +03:00
|
|
|
then
|
2021-09-29 03:41:30 +03:00
|
|
|
cat << EOF
|
|
|
|
style: success
|
|
|
|
value: $amount
|
|
|
|
ask:
|
|
|
|
en: A lot of donation this month: **$amount €**
|
|
|
|
EOF
|
|
|
|
else
|
|
|
|
cat << EOF
|
|
|
|
style: danger
|
|
|
|
value: $amount
|
|
|
|
ask:
|
|
|
|
en: Not so much donation this month: $amount €
|
|
|
|
EOF
|
2020-11-03 23:28:45 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-09-29 03:41:30 +03:00
|
|
|
get__prices() {
|
2023-02-07 12:16:26 +03:00
|
|
|
local prices = "$(grep "DONATION\['" "$install_dir/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')"
|
2021-09-29 03:41:30 +03:00
|
|
|
if [ "$prices" == "," ];
|
2020-11-03 23:28:45 +03:00
|
|
|
then
|
2021-09-29 03:41:30 +03:00
|
|
|
# Return YNH_NULL if you prefer to not return a value at all.
|
|
|
|
echo YNH_NULL
|
|
|
|
else
|
|
|
|
echo $prices
|
2020-11-03 23:28:45 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
|
|
|
#=================================================
|
2021-09-29 03:41:30 +03:00
|
|
|
validate__publishable_key() {
|
2020-11-03 23:28:45 +03:00
|
|
|
|
2023-09-13 12:23:41 +03:00
|
|
|
# We can imagine here we test if the key is really a publishable key
|
2021-09-29 03:41:30 +03:00
|
|
|
(is_secret_key $publishable_key) &&
|
|
|
|
echo 'This key seems to be a secret key'
|
2020-11-03 23:28:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
|
|
|
#=================================================
|
2021-09-29 03:41:30 +03:00
|
|
|
set__prices() {
|
|
|
|
|
|
|
|
#---------------------------------------------
|
2023-09-13 12:23:41 +03:00
|
|
|
# IMPORTANT: setters are triggered only if a change is detected
|
2021-09-29 03:41:30 +03:00
|
|
|
#---------------------------------------------
|
|
|
|
for price in $(echo $prices | sed "s/,/ /"); do
|
|
|
|
frequency=$(echo $price | cut -d/ -f1)
|
|
|
|
currency=$(echo $price | cut -d/ -f2)
|
|
|
|
price_id=$(echo $price | cut -d/ -f3)
|
2023-02-07 12:16:26 +03:00
|
|
|
sed "d/DONATION\['$frequency'\]\['$currency'\]" "$install_dir/settings.py"
|
2021-09-29 03:41:30 +03:00
|
|
|
|
2023-02-07 12:16:26 +03:00
|
|
|
echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$install_dir/settings.py"
|
2021-09-29 03:41:30 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
#---------------------------------------------
|
2023-09-13 12:23:41 +03:00
|
|
|
# IMPORTANT: to be able to upgrade properly, you have to save the value in settings too
|
2021-09-29 03:41:30 +03:00
|
|
|
#---------------------------------------------
|
|
|
|
ynh_app_setting_set $app prices $prices
|
2020-11-03 23:28:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#=================================================
|
2021-09-29 03:41:30 +03:00
|
|
|
# GENERIC FINALIZATION
|
2020-11-03 23:28:45 +03:00
|
|
|
#=================================================
|
2021-09-29 03:41:30 +03:00
|
|
|
ynh_app_config_run $1
|