1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00
lutim_ynh/scripts/config

186 lines
6.2 KiB
Text
Raw Normal View History

2018-09-30 11:52:12 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
2020-01-02 18:40:15 +01:00
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
2018-09-30 11:52:12 +02:00
#=================================================
# SPECIFIC CODE
#=================================================
# DECLARE GENERIC FUNCTION
#=================================================
config_file="$final_path/lutim.conf"
get_config_value() {
option_name="$1"
# Get the value of this option in the config file
grep "$option_name *=>" "$config_file" | cut -d'>' -f2 | sed s'/ //g' | cut -d',' -f1
}
#=================================================
# LOAD VALUES
#=================================================
# 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.
# always_encrypt
old_always_encrypt="$(get_config_value always_encrypt)"
always_encrypt="${YNH_CONFIG_MAIN_CONFIGURATION_ALWAYS_ENCRYPT:-$old_always_encrypt}"
# antiflood
old_antiflood="$(get_config_value anti_flood_delay)"
antiflood="${YNH_CONFIG_MAIN_CONFIGURATION_ANTIFLOOD:-$old_antiflood}"
# delay
old_delay="$(get_config_value default_delay)"
if [ $old_delay -eq 0 ]; then
old_delay=None
elif [ $old_delay -eq 1 ]; then
old_delay=Day
elif [ $old_delay -eq 7 ]; then
old_delay=Week
elif [ $old_delay -eq 30 ]; then
old_delay=Month
else
old_delay=Year
fi
delay="${YNH_CONFIG_MAIN_CONFIGURATION_DELAY:-$old_delay}"
# is_public
2020-01-02 18:40:15 +01:00
old_is_public="$(ynh_app_setting_get --app=$app --key=is_public)"
2018-09-30 11:52:12 +02:00
is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}"
# Overwrite settings.json file
2020-01-02 18:40:15 +01:00
old_overwrite_settings="$(ynh_app_setting_get --app=$app --key=overwrite_settings)"
2018-09-30 11:52:12 +02:00
overwrite_settings="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS:-$old_overwrite_settings}"
# Overwrite nginx configuration
2020-01-02 18:40:15 +01:00
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
2018-09-30 11:52:12 +02:00
overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
# Overwrite systemd configuration
2020-01-02 18:40:15 +01:00
old_overwrite_systemd="$(ynh_app_setting_get --app=$app --key=overwrite_systemd)"
2018-09-30 11:52:12 +02:00
overwrite_systemd="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD:-$old_overwrite_systemd}"
2019-01-30 19:27:17 +01:00
# Type of admin mail configuration
2020-01-02 18:40:15 +01:00
old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)"
2019-01-30 19:27:17 +01:00
admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
2018-09-30 11:52:12 +02:00
#=================================================
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
#=================================================
show_config() {
# here you are supposed to read some config file/database/other then print the values
2020-01-04 20:00:00 +01:00
# ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
2018-09-30 11:52:12 +02:00
2020-01-04 20:00:00 +01:00
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_ALWAYS_ENCRYPT=$always_encrypt"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_ANTIFLOOD=$antiflood"
ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_DELAY=$delay"
2018-09-30 11:52:12 +02:00
2020-01-04 20:00:00 +01:00
ynh_return "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public"
2018-09-30 11:52:12 +02:00
2020-01-04 20:00:00 +01:00
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD=$overwrite_systemd"
2019-01-30 19:27:17 +01:00
2020-01-04 20:00:00 +01:00
ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
2018-09-30 11:52:12 +02:00
}
#=================================================
# MODIFY THE CONFIGURATION
#=================================================
apply_config() {
restart_lutim=0
# Change configuration if needed
# always_encrypt
if [ "$always_encrypt" != "$old_always_encrypt" ]
then
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string=".*always_encrypt *=>.*" --replace_string=" always_encrypt => $always_encrypt," --target_file="$config_file"
2018-09-30 11:52:12 +02:00
restart_lutim=1
fi
# antiflood
if [ "$antiflood" != "$old_antiflood" ]
then
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$config_file"
2018-09-30 11:52:12 +02:00
# Disable anti_flood_delay if the delay is 0
if [ $antiflood = 0 ]; then
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$config_file"
2018-09-30 11:52:12 +02:00
fi
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=antiflood --value="$antiflood"
2018-09-30 11:52:12 +02:00
restart_lutim=1
fi
# delay
if [ "$delay" != "$old_delay" ]
then
if [ $delay = None ]; then
delay=0
elif [ $delay = Day ]; then
delay=1
elif [ $delay = Week ]; then
delay=7
elif [ $delay = Month ]; then
delay=30
else
delay=360
fi
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$config_file"
ynh_app_setting_set --app=$app --key=delay --value="$delay"
2018-09-30 11:52:12 +02:00
restart_lutim=1
fi
if [ $restart_lutim -eq 1 ]
then
# Wait for lutim to be fully started
2019-01-13 19:10:28 +01:00
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
2018-09-30 11:52:12 +02:00
fi
# Change public accessibility
if [ "$is_public" = "true" ]
then
yunohost app action run $app public_private --args is_public=1
else
yunohost app action run $app public_private --args is_public=0
fi
# Set overwrite_settings
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings"
2018-09-30 11:52:12 +02:00
# Set overwrite_nginx
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
2018-09-30 11:52:12 +02:00
# Set overwrite_systemd
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=overwrite_systemd --value="$overwrite_systemd"
2019-01-30 19:27:17 +01:00
# Set admin_mail_html
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
2018-09-30 11:52:12 +02:00
}
#=================================================
# GENERIC FINALIZATION
#=================================================
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
#=================================================
case $1 in
show) show_config;;
apply) apply_config;;
esac