2023-08-04 22:12:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# In simple cases, you don't need a config script.
|
|
|
|
|
|
|
|
# With a simple config_panel.toml, you can write in the app settings, in the
|
|
|
|
# upstream config file or replace complete files (logo ...) and restart services.
|
|
|
|
|
|
|
|
# The config scripts allows you to go further, to handle specific cases
|
|
|
|
# (validation of several interdependent fields, specific getter/setter for a value,
|
|
|
|
# display dynamic informations or choices, pre-loading of config type .cube... ).
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2023-08-29 03:44:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
|
|
|
#=================================================
|
|
|
|
get__host_properties() {
|
|
|
|
local short_setting="${1//_/.}"
|
|
|
|
local index="${1#*__}"
|
|
|
|
IFS='|' read -a values <<< "$(ynh_app_setting_get $app $short_setting)"
|
|
|
|
echo "value: \"${values[$(($index - 1))]:-}\""
|
|
|
|
}
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
|
|
|
#=================================================
|
2023-08-29 05:53:09 +02:00
|
|
|
get__multi_file() {
|
|
|
|
ynh_app_setting_get --app=$app --key=$1
|
|
|
|
}
|
2023-08-29 03:44:51 +02:00
|
|
|
set__multi_file() {
|
|
|
|
local short_setting="${1//_/.}"
|
|
|
|
local type="${2}"
|
2023-08-29 05:53:09 +02:00
|
|
|
local bind_files="$(echo $3 | sed 's/multi_file(//' | sed 's/)//')"
|
2023-08-29 03:44:51 +02:00
|
|
|
local value="${!1}"
|
|
|
|
local bind_file
|
|
|
|
ynh_app_setting_set --app=$app --key=$1 --value="$value"
|
|
|
|
ynh_print_info --message="Configuration key '$short_setting' edited in app settings"
|
|
|
|
if [ "$bind_files" != "" ]
|
|
|
|
then
|
2023-09-02 22:48:56 +02:00
|
|
|
for bind_file in ${bind_files//,/ }
|
2023-08-29 03:44:51 +02:00
|
|
|
do
|
|
|
|
ynh_read_var_in_file --file="${bind_file}" --key="${short_settings}"
|
|
|
|
ynh_print_info --message="Configuration key '$short_setting' edited in '${bind_file}'"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-08-29 05:53:09 +02:00
|
|
|
get__manage_subs() {
|
|
|
|
ynh_app_setting_get --app=$app --key=$1
|
|
|
|
}
|
2023-08-29 03:44:51 +02:00
|
|
|
set__manage_subs() {
|
|
|
|
ynh_print_info --message="Configuration key '$1' edited in app settings"
|
|
|
|
ynh_app_setting_set --app=$app --key=$1 --value="${!1}"
|
|
|
|
|
|
|
|
ynh_print_info --message="Subs added in organization.properties"
|
|
|
|
update_subs
|
|
|
|
}
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# OVERWRITING APPLY STEP
|
|
|
|
#=================================================
|
|
|
|
ynh_app_config_apply() {
|
|
|
|
|
|
|
|
_ynh_app_config_apply
|
|
|
|
|
|
|
|
# Update date of properties files
|
|
|
|
local date=$(date '+%Y-%m-%dT%H:%M:%S')
|
|
|
|
ynh_write_var_in_file --file="$install_dir/public/organization.properties" --key="file.datetime" --value="$date"
|
2023-09-04 00:40:26 +02:00
|
|
|
local apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g" | grep -v chatonsinfos)
|
2023-08-29 03:44:51 +02:00
|
|
|
for _app_id in $apps
|
|
|
|
do
|
|
|
|
ynh_write_var_in_file --file="$install_dir/public/$_app_id.properties" --key="file.datetime" --value="$date"
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
2023-08-04 22:12:34 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
ynh_app_config_run $1
|