#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS #================================================= app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # 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}" # Overwrite settings.json file old_overwrite_settings="$(ynh_app_setting_get --app=$app --key=overwrite_settings)" overwrite_settings="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS:-$old_overwrite_settings}" # Overwrite nginx configuration old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)" overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}" # Overwrite systemd configuration old_overwrite_systemd="$(ynh_app_setting_get --app=$app --key=overwrite_systemd)" overwrite_systemd="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD:-$old_overwrite_systemd}" # Type of admin mail configuration old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)" admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}" #================================================= # 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_CONFIGURATION_ALWAYS_ENCRYPT=$always_encrypt" ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_ANTIFLOOD=$antiflood" ynh_return "YNH_CONFIG_MAIN_CONFIGURATION_DELAY=$delay" 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" ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" } #================================================= # MODIFY THE CONFIGURATION #================================================= apply_config() { #================================================= # MODIFY LUTIM CONFIGURATION #================================================= restart_lutim=0 # Change configuration if needed # always_encrypt if [ "$always_encrypt" != "$old_always_encrypt" ] then ynh_replace_string --match_string=".*always_encrypt *=>.*" --replace_string=" always_encrypt => $always_encrypt," --target_file="$config_file" restart_lutim=1 fi # antiflood if [ "$antiflood" != "$old_antiflood" ] then ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$config_file" # Disable anti_flood_delay if the delay is 0 if [ $antiflood = 0 ]; then ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$config_file" fi ynh_app_setting_set --app=$app --key=antiflood --value="$antiflood" 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 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" restart_lutim=1 fi if [ $restart_lutim -eq 1 ] then # Wait for lutim to be fully started ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120" fi #================================================= # MODIFY OVERWRITTING SETTINGS #================================================= # Set overwrite_settings ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings" # Set overwrite_nginx ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx" # Set overwrite_systemd ynh_app_setting_set --app=$app --key=overwrite_systemd --value="$overwrite_systemd" #================================================= # MODIFY EMAIL SETTING #================================================= # Set admin_mail_html ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html" } #================================================= # GENERIC FINALIZATION #================================================= # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT #================================================= case $1 in show) show_config;; apply) apply_config;; esac