#!/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} final_path=$(ynh_app_setting_get $app 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)" old_always_encrypt=$(bool_to_true_false $old_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 old_is_public="$(ynh_app_setting_get $app is_public)" old_is_public=$(bool_to_true_false $old_is_public) is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}" # Overwrite settings.json file old_overwrite_settings="$(ynh_app_setting_get $app overwrite_settings)" old_overwrite_settings=$(bool_to_true_false $old_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 overwrite_nginx)" old_overwrite_nginx=$(bool_to_true_false $old_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 overwrite_systemd)" old_overwrite_systemd=$(bool_to_true_false $old_overwrite_systemd) overwrite_systemd="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD:-$old_overwrite_systemd}" #================================================= # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND #================================================= show_config() { # here you are supposed to read some config file/database/other then print the values # echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" echo "YNH_CONFIG_MAIN_CONFIGURATION_ALWAYS_ENCRYPT=$always_encrypt" echo "YNH_CONFIG_MAIN_CONFIGURATION_ANTIFLOOD=$antiflood" echo "YNH_CONFIG_MAIN_CONFIGURATION_DELAY=$delay" echo "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public" echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings" echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx" echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD=$overwrite_systemd" } #================================================= # MODIFY THE CONFIGURATION #================================================= apply_config() { restart_lutim=0 # Change configuration if needed # always_encrypt if [ "$always_encrypt" != "$old_always_encrypt" ] then always_encrypt=$(bool_to_01 $always_encrypt) ynh_replace_string ".*always_encrypt *=>.*" " always_encrypt => $always_encrypt," "$config_file" restart_lutim=1 fi # antiflood if [ "$antiflood" != "$old_antiflood" ] then ynh_replace_string ".*anti_flood_delay *=>.*" " anti_flood_delay => $antiflood," "$config_file" # Disable anti_flood_delay if the delay is 0 if [ $antiflood = 0 ]; then ynh_replace_string "\(anti_flood_delay *=>.*\)" "#\1" "$config_file" fi ynh_app_setting_set $app antiflood "$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 ".*default_delay *=>.*" " default_delay => $delay," "$config_file" ynh_app_setting_set $app delay "$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 # 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 overwrite_settings=$(bool_to_01 $overwrite_settings) ynh_app_setting_set $app overwrite_settings "$overwrite_settings" # Set overwrite_nginx overwrite_nginx=$(bool_to_01 $overwrite_nginx) ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx" # Set overwrite_systemd overwrite_systemd=$(bool_to_01 $overwrite_systemd) ynh_app_setting_set $app overwrite_systemd "$overwrite_systemd" } #================================================= # GENERIC FINALIZATION #================================================= # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT #================================================= case $1 in show) show_config;; apply) apply_config;; esac