#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers # Load common variables for all scripts. source _variables #================================================= # 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/settings.json" 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. # Export old_export="$(ynh_app_setting_get $app export)" export="${YNH_CONFIG_MAIN_EXPORT_EXPORT:-$old_export}" # padOptions noColors old_pad_config_nocolors="$(get_config_value noColors)" pad_config_nocolors="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_NOCOLORS:-$old_pad_config_nocolors}" # padOptions showLineNumbers old_pad_config_showlinenumbers="$(get_config_value showLineNumbers)" pad_config_showlinenumbers="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOWLINENUMBERS:-$old_pad_config_showlinenumbers}" # padOptions chatAndUsers old_pad_config_chatandusers="$(get_config_value chatAndUsers)" pad_config_chatandusers="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_CHATANDUSERS:-$old_pad_config_chatandusers}" # padOptions alwaysShowChat old_pad_config_alwaysshowchat="$(get_config_value alwaysShowChat)" pad_config_alwaysshowchat="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_ALWAYSSHOWCHAT:-$old_pad_config_alwaysshowchat}" # Plugin option ep_markdown_default old_pad_config_show_markdown="$(get_config_value ep_markdown_default)" pad_config_show_markdown="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOW_MARKDOWN:-$old_pad_config_show_markdown}" # Plugin option ep_page_view_default old_pad_config_pageview="$(get_config_value ep_page_view_default)" pad_config_pageview="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_PAGEVIEW:-$old_pad_config_pageview}" # Mypads if [ -d $final_path/node_modules/ep_mypads ] then old_mypads=true else old_mypads=false fi mypads="${YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_MYPADS:-$old_mypads}" # Ldap for Mypads if grep -q "//noldap" $config_file then old_useldap=false else old_useldap=true fi useldap="${YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_USELDAP:-$old_useldap}" # is_public old_is_public="$(ynh_app_setting_get --app=$app --key=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=$app --key=overwrite_settings)" overwrite_settings="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS:-$old_overwrite_settings}" # Overwrite credentials.json file old_overwrite_credentials="$(ynh_app_setting_get --app=$app --key=overwrite_credentials)" overwrite_credentials="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_CREDENTIALS:-$old_overwrite_credentials}" # 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}" #================================================= # 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_EXPORT_EXPORT=$export" echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_NOCOLORS=$pad_config_nocolors" echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOWLINENUMBERS=$pad_config_showlinenumbers" echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_CHATANDUSERS=$pad_config_chatandusers" echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_ALWAYSSHOWCHAT=$pad_config_alwaysshowchat" echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOW_MARKDOWN=$pad_config_show_markdown" echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_PAGEVIEW=$pad_config_pageview" echo "YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_MYPADS=$mypads" echo "YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_USELDAP=$useldap" 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_CREDENTIALS=$overwrite_credentials" 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_etherpad=0 # Change configuration if needed # padOptions noColors if [ "$pad_config_nocolors" != "$old_pad_config_nocolors" ] then ynh_replace_string --match_string="\(\"noColors\" *: \).*," --replace_string="\1$pad_config_nocolors," --target_file="$config_file" ynh_app_setting_set --app=$app --key=pad_config_nocolors --value="$pad_config_nocolors" restart_etherpad=1 fi # padOptions showLineNumbers if [ "$pad_config_showlinenumbers" != "$old_pad_config_showlinenumbers" ] then ynh_replace_string --match_string="\(\"showLineNumbers\" *: \).*," --replace_string="\1$pad_config_showlinenumbers," --target_file="$config_file" ynh_app_setting_set --app=$app --key=pad_config_showlinenumbers --value="$pad_config_showlinenumbers" restart_etherpad=1 fi # padOptions chatAndUsers if [ "$pad_config_chatandusers" != "$old_pad_config_chatandusers" ] then ynh_replace_string --match_string="\(\"chatAndUsers\" *: \).*," --replace_string="\1$pad_config_chatandusers," --target_file="$config_file" ynh_app_setting_set --app=$app --key=pad_config_chatandusers --value="$pad_config_chatandusers" restart_etherpad=1 fi # padOptions alwaysShowChat if [ "$pad_config_alwaysshowchat" != "$old_pad_config_alwaysshowchat" ] then ynh_replace_string --match_string="\(\"alwaysShowChat\" *: \).*," --replace_string="\1$pad_config_alwaysshowchat," --target_file="$config_file" ynh_app_setting_set --app=$app --key=pad_config_alwaysshowchat --value="$pad_config_alwaysshowchat" restart_etherpad=1 fi # Plugin option ep_markdown_default if [ "$pad_config_show_markdown" != "$old_pad_config_show_markdown" ] then ynh_replace_string --match_string="\(\"ep_markdown_default\" *: \).*," --replace_string="\1$pad_config_show_markdown," --target_file="$config_file" ynh_app_setting_set --app=$app --key=pad_config_show_markdown --value="$pad_config_show_markdown" restart_etherpad=1 fi # Plugin option ep_page_view_default if [ "$pad_config_pageview" != "$old_pad_config_pageview" ] then ynh_replace_string --match_string="\(\"ep_page_view_default\" *: \).*," --replace_string="\1$pad_config_pageview," "$config_file" ynh_app_setting_set --app=$app --key=pad_config_pageview --value="$pad_config_pageview" restart_etherpad=1 fi # Export if [ "$export" != "$old_export" ] then if [ "$export" = "abiword" ] then # if abiword isn't installed, call the action add_remove_abiword. if ! which abiword > /dev/null then yunohost app action run $app add_remove_abiword fi ynh_replace_string --match_string="\(\"abiword\" *: \).*," --replace_string="\1\"$(which abiword)\"," --target_file="$config_file" ynh_replace_string --match_string="\(\"soffice\" *: \).*," --replace_string="\1null," --target_file="$config_file" elif [ "$export" = "libreoffice" ] then # if libreoffice isn't installed, call the action add_remove_libreoffice. if ! which soffice > /dev/null then yunohost app action run $app add_remove_libreoffice fi ynh_replace_string --match_string="\(\"abiword\" *: \).*," --replace_string="\1null," --target_file="$config_file" ynh_replace_string --match_string="\(\"soffice\" *: \).*," --replace_string="\1\"$(which soffice)\"," --target_file="$config_file" else ynh_replace_string --match_string="\(\"abiword\" *: \).*," --replace_string="\1null," --target_file="$config_file" ynh_replace_string --match_string="\(\"soffice\" *: \).*," --replace_string="\1null," --target_file="$config_file" fi restart_etherpad=1 fi # Mypads if [ "$mypads" != "$old_mypads" ] then ynh_use_nodejs pushd "$final_path" if [ "$mypads" = "true" ] then npm install ep_mypads@${mypads_version} else npm uninstall ep_mypads fi popd chown -R $app: $final_path/node_modules restart_etherpad=1 fi # Ldap for Mypads if [ "$useldap" != "$old_useldap" ] then if [ "$useldap" = "true" ] then ynh_replace_string --match_string="//noldap\(.*\)" --replace_string="\1 //useldap" --target_file="$final_path/settings.json" else ynh_replace_string --match_string="\(.*\) //useldap" --replace_string="//noldap\1" --target_file="$final_path/settings.json" fi restart_etherpad=1 fi if [ $restart_etherpad -eq 1 ] then # Wait for etherpad to be fully started ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "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 ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings" # Set overwrite_credentials ynh_app_setting_set --app=$app --key=overwrite_credentials --value="$overwrite_credentials" # 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" } #================================================= # GENERIC FINALIZATION #================================================= # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT #================================================= case $1 in show) show_config;; apply) apply_config;; esac