From 21a002970bf25e9bc5cb462eb294ff3762fd51cf Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 7 Aug 2018 13:13:25 +0200 Subject: [PATCH 1/3] Add actions and config-panel --- actions.json | 33 ++++ config_panel.json | 87 +++++++++ scripts/actions/add_remove_abiword | 94 +++++++++ scripts/actions/add_remove_libreoffice | 94 +++++++++ scripts/actions/list_all_pads | 35 ++++ scripts/config | 257 +++++++++++++++++++++++++ scripts/install | 2 +- scripts/upgrade | 2 +- 8 files changed, 602 insertions(+), 2 deletions(-) create mode 100644 actions.json create mode 100644 config_panel.json create mode 100755 scripts/actions/add_remove_abiword create mode 100755 scripts/actions/add_remove_libreoffice create mode 100755 scripts/actions/list_all_pads create mode 100644 scripts/config diff --git a/actions.json b/actions.json new file mode 100644 index 0000000..518828c --- /dev/null +++ b/actions.json @@ -0,0 +1,33 @@ +[{ + "id": "add_remove_abiword", + "name": "Install/remove abiword", + "command": "/bin/bash scripts/actions/add_remove_abiword", + "user": "root", + "accepted_return_codes": [0], + "description": { + "en": "Install or remove abiword.", + "fr": "Installe ou supprime abiword." + } +}, +{ + "id": "add_remove_libreoffice", + "name": "Install/remove libreoffice", + "command": "/bin/bash scripts/actions/add_remove_libreoffice", + "user": "root", + "accepted_return_codes": [0], + "description": { + "en": "Install or remove libreoffice.", + "fr": "Installe ou supprime libreoffice." + } +}, +{ + "id": "list_all_pads", + "name": "List all existing pads", + "command": "/bin/bash scripts/actions/list_all_pads", + "user": "root", + "accepted_return_codes": [0], + "description": { + "en": "List all existing pads.", + "fr": "Liste tout les pads existants." + } +}] diff --git a/config_panel.json b/config_panel.json new file mode 100644 index 0000000..1d34402 --- /dev/null +++ b/config_panel.json @@ -0,0 +1,87 @@ +{ + "name": "Etherpad configuration panel", + "version": "0.1", + "panel": [{ + "name": "Etherpad configuration", + "id": "main", + "sections": [{ + "name": "Export", + "id": "export", + "options": [{ + "name": "Use abiword (~260Mo) or libreoffice (~400Mo) (more stable) to expand export possibilities (pdf, doc) ?", + "help": "We can't use a choices field for now. In the meantime please choose between one of this values:
none, abiword, libreoffice.", + "id": "export", + "type": "text", + "//": "\"choices\" : [\"none\", \"abiword\", \"libreoffice\"]", + "default" : "none" + }] + }, + { + "name": "Default pad configuration", + "id": "pad_configuration", + "options": [{ + "name": "Hide authorship colors ?", + "id": "pad_config_nocolors", + "type": "bool", + "default": false + }, + { + "name": "Show line numbers ?", + "id": "pad_config_showlinenumbers", + "type": "bool", + "default": true + }, + { + "name": "Show chat and users ?", + "id": "pad_config_chatandusers", + "type": "bool", + "default": false + }, + { + "name": "Always show chat ?", + "id": "pad_config_alwaysshowchat", + "type": "bool", + "default": false + }, + { + "name": "Show markdown syntax ?", + "id": "pad_config_show_markdown", + "type": "bool", + "default": false + }, + { + "name": "Page view ?", + "id": "pad_config_pageview", + "type": "bool", + "default": false + }] + }, + { + "name": "Mypads configuration", + "id": "mypads_configuration", + "options": [{ + "name": "Enable Mypads plugin ?", + "id": "mypads", + "type": "bool", + "default": true + }, + { + "name": "Use ldap with Mypads ?", + "id": "useldap", + "type": "bool", + "default": true + }] + }, + { + "name": "Public access", + "id": "is_public", + "options": [{ + "name": "Is it a public website ?", + "id": "is_public", + "type": "bool", + "default": true + }] + }] + } +] +} diff --git a/scripts/actions/add_remove_abiword b/scripts/actions/add_remove_abiword new file mode 100755 index 0000000..1e4b3cf --- /dev/null +++ b/scripts/actions/add_remove_abiword @@ -0,0 +1,94 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_ID + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +# Check the dependencies of the meta packages of etherpad_mypads with apt-cache +if apt-cache depends ${app//_/-}-ynh-deps | grep --quiet abiword +then + # abiword is already a dependence of etherpad_mypads. + # abiword should be removed. + abiword=0 + ynh_print_info "Abiword will be removed." >&2 +else + # abiword isn't a dependence of etherpad_mypads. + # abiword should be installed. + ynh_print_info "Abiword will be installed." >&2 + abiword=1 +fi + +if apt-cache depends ${app//_/-}-ynh-deps | grep --quiet libreoffice-writer +then + # libreoffice is already a dependence of etherpad_mypads. + # Keep it + libreoffice=1 +else + # libreoffice isn't a dependence of etherpad_mypads. + # Do not add it + libreoffice=0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# INSTALL OR REMOVE ABIWORD +#================================================= + +# Load common variables, and especially abiword dependencies. +source scripts/_variables + +dependencies="" +if [ $abiword -eq 1 ] +then + # Add abiword dependencies if abiword has to be installed + dependencies="$dependencies $abiword_app_depencencies" +fi +if [ $libreoffice -eq 1 ] +then + # Add libreoffice dependencies if libreoffice is already installed to keep it as a dependence. + dependencies="$dependencies $libreoffice_app_dependencies" +fi + +# Rebuild the meta package and install the new dependencies +( cd scripts # Move to scripts directory to allow the helper to find the manifest where it expects to find it. +ynh_install_app_dependencies $dependencies) + +# Remove all unused dependencies +ynh_package_autopurge + +#================================================= +# SET THE DEFAULT EXPORT APP +#================================================= + +if [ $abiword -eq 1 ] +then + # Set abiword as default export app + yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=abiword" +elif [ $libreoffice -eq 1 ] +then + # Set libreoffice as default export app + yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=libreoffice" +else + # Remove any export app + yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=none" +fi diff --git a/scripts/actions/add_remove_libreoffice b/scripts/actions/add_remove_libreoffice new file mode 100755 index 0000000..6f32eb5 --- /dev/null +++ b/scripts/actions/add_remove_libreoffice @@ -0,0 +1,94 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_ID + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +# Check the dependencies of the meta packages of etherpad_mypads with apt-cache +if apt-cache depends ${app//_/-}-ynh-deps | grep --quiet libreoffice-writer +then + # libreoffice is already a dependence of etherpad_mypads. + # libreoffice should be removed. + libreoffice=0 + ynh_print_info "Libreoffice writer will be removed." >&2 +else + # libreoffice isn't a dependence of etherpad_mypads. + # libreoffice should be installed. + ynh_print_info "Libreoffice writer will be installed." >&2 + libreoffice=1 +fi + +if apt-cache depends ${app//_/-}-ynh-deps | grep --quiet abiword +then + # abiword is already a dependence of etherpad_mypads. + # Keep it + abiword=1 +else + # abiword isn't a dependence of etherpad_mypads. + # Do not add it + abiword=0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# INSTALL OR REMOVE LIBREOFFICE +#================================================= + +# Load common variables, and especially libreoffice dependencies. +source scripts/_variables + +dependencies="" +if [ $libreoffice -eq 1 ] +then + # Add libreoffice dependencies if libreoffice has to be installed + dependencies="$dependencies $libreoffice_app_dependencies" +fi +if [ $abiword -eq 1 ] +then + # Add abiword dependencies if abiword is already installed to keep it as a dependence. + dependencies="$dependencies $abiword_app_depencencies" +fi + +# Rebuild the meta package and install the new dependencies +( cd scripts # Move to scripts directory to allow the helper to find the manifest where it expects to find it. +ynh_install_app_dependencies $dependencies) + +# Remove all unused dependencies +ynh_package_autopurge + +#================================================= +# SET THE DEFAULT EXPORT APP +#================================================= + +if [ $libreoffice -eq 1 ] +then + # Set libreoffice as default export app + yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=libreoffice" +elif [ $abiword -eq 1 ] +then + # Set abiword as default export app + yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=abiword" +else + # Remove any export app + yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=none" +fi diff --git a/scripts/actions/list_all_pads b/scripts/actions/list_all_pads new file mode 100755 index 0000000..2d8160e --- /dev/null +++ b/scripts/actions/list_all_pads @@ -0,0 +1,35 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_ID + +db_name=$(ynh_app_setting_get $app db_name) +db_pwd=$(ynh_app_setting_get $app mysqlpwd) + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +#================================================= +# SPECIFIC ACTION +#================================================= +# LIST ALL PADS FROM THE DATABASE +#================================================= + +mysql -u $db_name -p$db_pwd $db_name --silent -e 'select distinct substring(store.key,5,locate(":",store.key,5)-5) as "pads" from store where store.key like "pad:%"' | sed 's/^/>> /g' >&2 diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..46d205a --- /dev/null +++ b/scripts/config @@ -0,0 +1,257 @@ +#!/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_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 is_public)" + if [ $old_is_public -eq 1 ] + then + old_is_public=true + else + old_is_public=false + fi + is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}" + +#================================================= +# 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" +} + +#================================================= +# 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 "\(\"noColors\" *: \).*," "\1$pad_config_nocolors," "$config_file" + restart_etherpad=1 + fi + + # padOptions showLineNumbers + if [ "$pad_config_showlinenumbers" != "$old_pad_config_showlinenumbers" ] + then + ynh_replace_string "\(\"showLineNumbers\" *: \).*," "\1$pad_config_showlinenumbers," "$config_file" + restart_etherpad=1 + fi + + # padOptions chatAndUsers + if [ "$pad_config_chatandusers" != "$old_pad_config_chatandusers" ] + then + ynh_replace_string "\(\"chatAndUsers\" *: \).*," "\1$pad_config_chatandusers," "$config_file" + restart_etherpad=1 + fi + + # padOptions alwaysShowChat + if [ "$pad_config_alwaysshowchat" != "$old_pad_config_alwaysshowchat" ] + then + ynh_replace_string "\(\"alwaysShowChat\" *: \).*," "\1$pad_config_alwaysshowchat," "$config_file" + restart_etherpad=1 + fi + + # Plugin option ep_markdown_default + if [ "$pad_config_show_markdown" != "$old_pad_config_show_markdown" ] + then + ynh_replace_string "\(\"ep_markdown_default\" *: \).*," "\1$pad_config_show_markdown," "$config_file" + restart_etherpad=1 + fi + + # Plugin option ep_page_view_default + if [ "$pad_config_pageview" != "$old_pad_config_pageview" ] + then + ynh_replace_string "\(\"ep_page_view_default\" *: \).*," "\1$pad_config_pageview," "$config_file" + 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 "\(\"abiword\" *: \).*," "\1\"$(which abiword)\"," "$config_file" + ynh_replace_string "\(\"soffice\" *: \).*," "\1null," "$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 "\(\"abiword\" *: \).*," "\1null," "$config_file" + ynh_replace_string "\(\"soffice\" *: \).*," "\1\"$(which soffice)\"," "$config_file" + else + ynh_replace_string "\(\"abiword\" *: \).*," "\1null," "$config_file" + ynh_replace_string "\(\"soffice\" *: \).*," "\1null," "$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 "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json" + else + ynh_replace_string "\(.*\) //useldap" "//noldap\1" "$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 + is_public=1 + else + is_public=0 + fi + if [ $is_public -eq 1 ]; then + ynh_app_setting_set $app skipped_uris "/" + else + ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO... + fi + ynh_app_setting_set $app is_public $is_public + yunohost app ssowatconf +} + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT +#================================================= + +case $1 in + show) show_config;; + apply) apply_config;; +esac diff --git a/scripts/install b/scripts/install index 929c3af..693dc65 100644 --- a/scripts/install +++ b/scripts/install @@ -186,7 +186,7 @@ ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" # Use ldap for mypads if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] then - ynh_replace_string "//noldap" "" "$final_path/settings.json" + ynh_replace_string "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json" fi ynh_store_file_checksum "$final_path/settings.json" # Store config file checksum diff --git a/scripts/upgrade b/scripts/upgrade index 7941647..0df9520 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -201,7 +201,7 @@ ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" # Use ldap for mypads if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] then - ynh_replace_string "//noldap" "" "$final_path/settings.json" + ynh_replace_string "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json" fi ynh_store_file_checksum "$final_path/settings.json" # Recalculate and store the config file checksum into the app settings From 37bb93d4cc7803663019c7be7631d3c1a56ef655 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 21 Aug 2018 19:57:15 +0200 Subject: [PATCH 2/3] Use YNH_APP_INSTANCE_NAME instead of YNH_APP_ID --- scripts/actions/add_remove_abiword | 2 +- scripts/actions/add_remove_libreoffice | 2 +- scripts/actions/list_all_pads | 2 +- scripts/config | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/actions/add_remove_abiword b/scripts/actions/add_remove_abiword index 1e4b3cf..8912185 100755 --- a/scripts/actions/add_remove_abiword +++ b/scripts/actions/add_remove_abiword @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_ID +app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF ARGUMENTS ARE CORRECT diff --git a/scripts/actions/add_remove_libreoffice b/scripts/actions/add_remove_libreoffice index 6f32eb5..86f493d 100755 --- a/scripts/actions/add_remove_libreoffice +++ b/scripts/actions/add_remove_libreoffice @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_ID +app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF ARGUMENTS ARE CORRECT diff --git a/scripts/actions/list_all_pads b/scripts/actions/list_all_pads index 2d8160e..ffdda94 100755 --- a/scripts/actions/list_all_pads +++ b/scripts/actions/list_all_pads @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_ID +app=$YNH_APP_INSTANCE_NAME db_name=$(ynh_app_setting_get $app db_name) db_pwd=$(ynh_app_setting_get $app mysqlpwd) diff --git a/scripts/config b/scripts/config index 46d205a..b20f344 100644 --- a/scripts/config +++ b/scripts/config @@ -15,7 +15,7 @@ source _variables # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_ID +app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) From 452bae715460b68ca3ad36ef73e11e7dc0926cdb Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 29 Sep 2018 21:02:18 +0200 Subject: [PATCH 3/3] Panel-config + actions fully tested --- actions.json | 31 +++++ config_panel.json | 34 +++++- scripts/_common.sh | 18 +++ scripts/actions/add_remove_abiword | 2 +- scripts/actions/add_remove_libreoffice | 2 +- scripts/actions/list_all_pads | 2 +- scripts/actions/public_private | 58 +++++++++ scripts/actions/reset_default_config | 72 ++++++++++++ scripts/config | 152 ++++++++++++++---------- scripts/install | 4 + scripts/upgrade | 157 ++++++++++++++++++------- 11 files changed, 424 insertions(+), 108 deletions(-) create mode 100755 scripts/actions/public_private create mode 100755 scripts/actions/reset_default_config diff --git a/actions.json b/actions.json index 518828c..393a635 100644 --- a/actions.json +++ b/actions.json @@ -30,4 +30,35 @@ "en": "List all existing pads.", "fr": "Liste tout les pads existants." } +}, +{ + "id": "reset_default_config", + "name": "Reset the config file and restore a default one.", + "command": "/bin/bash scripts/actions/reset_default_config \"settings.json\"", + "user": "root", + "accepted_return_codes": [0], + "description": { + "en": "Reset the config file settings.json.", + "fr": "Réinitialise le fichier de configuration settings.json." + } +}, +{ + "id": "public_private", + "name": "Move to public or private", + "command": "/bin/bash scripts/actions/public_private", + "user": "root", + "accepted_return_codes": [0], + "description": { + "en": "Change the public access of the app." + }, + "arguments": [ + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public app ?" + }, + "default": true + } + ] }] diff --git a/config_panel.json b/config_panel.json index 1d34402..4beaf4f 100644 --- a/config_panel.json +++ b/config_panel.json @@ -76,11 +76,43 @@ "name": "Public access", "id": "is_public", "options": [{ - "name": "Is it a public website ?", + "name": "Is it a public app ?", "id": "is_public", "type": "bool", "default": true }] + }, + { + "name": "Overwriting config files", + "id": "overwrite_files", + "options": [{ + "name": "Overwrite the config file settings.json ?", + "help": "If the file is overwritten, a backup will be created.", + "id": "overwrite_settings", + "type": "bool", + "default": true + }, + { + "name": "Overwrite the config file credentials.json ?", + "help": "If the file is overwritten, a backup will be created.", + "id": "overwrite_credentials", + "type": "bool", + "default": true + }, + { + "name": "Overwrite the nginx config file ?", + "help": "If the file is overwritten, a backup will be created.", + "id": "overwrite_nginx", + "type": "bool", + "default": true + }, + { + "name": "Overwrite the systemd config file ?", + "help": "If the file is overwritten, a backup will be created.", + "id": "overwrite_systemd", + "type": "bool", + "default": true + }] }] } ] diff --git a/scripts/_common.sh b/scripts/_common.sh index 44a54cc..49ff2a2 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -22,6 +22,24 @@ CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant fi } +#================================================= +# BOOLEAN CONVERTER +#================================================= + +bool_to_01 () { + local var="$1" + [ "$var" = "true" ] && var=1 + [ "$var" = "false" ] && var=0 + echo "$var" +} + +bool_to_true_false () { + local var="$1" + [ "$var" = "1" ] && var=true + [ "$var" = "0" ] && var=false + echo "$var" +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/actions/add_remove_abiword b/scripts/actions/add_remove_abiword index 8912185..2224ee7 100755 --- a/scripts/actions/add_remove_abiword +++ b/scripts/actions/add_remove_abiword @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_INSTANCE_NAME +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} #================================================= # CHECK IF ARGUMENTS ARE CORRECT diff --git a/scripts/actions/add_remove_libreoffice b/scripts/actions/add_remove_libreoffice index 86f493d..26677df 100755 --- a/scripts/actions/add_remove_libreoffice +++ b/scripts/actions/add_remove_libreoffice @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_INSTANCE_NAME +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} #================================================= # CHECK IF ARGUMENTS ARE CORRECT diff --git a/scripts/actions/list_all_pads b/scripts/actions/list_all_pads index ffdda94..6bb8c21 100755 --- a/scripts/actions/list_all_pads +++ b/scripts/actions/list_all_pads @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_INSTANCE_NAME +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} db_name=$(ynh_app_setting_get $app db_name) db_pwd=$(ynh_app_setting_get $app mysqlpwd) diff --git a/scripts/actions/public_private b/scripts/actions/public_private new file mode 100755 index 0000000..0b004cc --- /dev/null +++ b/scripts/actions/public_private @@ -0,0 +1,58 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +# Get is_public +is_public=${YNH_ACTION_IS_PUBLIC} + +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +is_public_old=$(ynh_app_setting_get $app is_public) + +if [ $is_public -eq $is_public_old ] +then + ynh_die "is_public is already set as $is_public." 0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# MOVE TO PUBLIC OR PRIVATE +#================================================= + +if [ $is_public -eq 0 ] +then + ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO... +else + ynh_app_setting_set $app skipped_uris "/" +fi + +# Regen ssowat configuration +yunohost app ssowatconf + +# Update the config of the app +ynh_app_setting_set $app is_public $is_public + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/actions/reset_default_config b/scripts/actions/reset_default_config new file mode 100755 index 0000000..e0f76ef --- /dev/null +++ b/scripts/actions/reset_default_config @@ -0,0 +1,72 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_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) +port=$(ynh_app_setting_get $app port) +export=$(ynh_app_setting_get $app export) +language=$(ynh_app_setting_get $app language) +mypads=$(ynh_app_setting_get $app mypads) +useldap=$(ynh_app_setting_get $app useldap) + +#================================================= +# SORT OUT THE CONFIG FILE TO HANDLE +#================================================= + +file="$1" + +if [ "$file" = "settings.json" ]; then + config_file="$final_path/settings.json" +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# RESET THE CONFIG FILE +#================================================= + +# Verify the checksum and backup the file if it's different +ynh_backup_if_checksum_is_different "$config_file" + +if [ "$file" = "settings.json" ] +then + # Get the default file and overwrite the current config + cp /etc/yunohost/apps/$app/conf/settings.json "$config_file" + + # Recreate the default config + ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" + if [ "$export" = "abiword" ] + then + abiword_path=`which abiword` # Get abiword binary path + ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad + elif [ "$export" = "libreoffice" ] + then + soffice_path=`which soffice` # Get soffice binary path + ynh_replace_string "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad + fi + ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" + + # Use ldap for mypads + if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] + then + ynh_replace_string "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json" + fi +fi + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "$config_file" + +# Wait for etherpad to be fully started +ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" diff --git a/scripts/config b/scripts/config index b20f344..709cb22 100644 --- a/scripts/config +++ b/scripts/config @@ -15,7 +15,7 @@ source _variables # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_INSTANCE_NAME +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} final_path=$(ynh_app_setting_get $app final_path) @@ -38,60 +38,75 @@ get_config_value() { # 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. +# 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}" +# 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}" +# 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}" +# 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 is_public)" - if [ $old_is_public -eq 1 ] - then - old_is_public=true - else - old_is_public=false - fi - is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}" +# 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 credentials.json file +old_overwrite_credentials="$(ynh_app_setting_get $app overwrite_credentials)" +old_overwrite_credentials=$(bool_to_true_false $old_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 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 @@ -114,6 +129,11 @@ show_config() { 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" } #================================================= @@ -128,6 +148,7 @@ apply_config() { if [ "$pad_config_nocolors" != "$old_pad_config_nocolors" ] then ynh_replace_string "\(\"noColors\" *: \).*," "\1$pad_config_nocolors," "$config_file" + ynh_app_setting_set $app pad_config_nocolors "$pad_config_nocolors" restart_etherpad=1 fi @@ -135,6 +156,7 @@ apply_config() { if [ "$pad_config_showlinenumbers" != "$old_pad_config_showlinenumbers" ] then ynh_replace_string "\(\"showLineNumbers\" *: \).*," "\1$pad_config_showlinenumbers," "$config_file" + ynh_app_setting_set $app pad_config_showlinenumbers "$pad_config_showlinenumbers" restart_etherpad=1 fi @@ -142,6 +164,7 @@ apply_config() { if [ "$pad_config_chatandusers" != "$old_pad_config_chatandusers" ] then ynh_replace_string "\(\"chatAndUsers\" *: \).*," "\1$pad_config_chatandusers," "$config_file" + ynh_app_setting_set $app pad_config_chatandusers "$pad_config_chatandusers" restart_etherpad=1 fi @@ -149,6 +172,7 @@ apply_config() { if [ "$pad_config_alwaysshowchat" != "$old_pad_config_alwaysshowchat" ] then ynh_replace_string "\(\"alwaysShowChat\" *: \).*," "\1$pad_config_alwaysshowchat," "$config_file" + ynh_app_setting_set $app pad_config_alwaysshowchat "$pad_config_alwaysshowchat" restart_etherpad=1 fi @@ -156,6 +180,7 @@ apply_config() { if [ "$pad_config_show_markdown" != "$old_pad_config_show_markdown" ] then ynh_replace_string "\(\"ep_markdown_default\" *: \).*," "\1$pad_config_show_markdown," "$config_file" + ynh_app_setting_set $app pad_config_show_markdown "$pad_config_show_markdown" restart_etherpad=1 fi @@ -163,6 +188,7 @@ apply_config() { if [ "$pad_config_pageview" != "$old_pad_config_pageview" ] then ynh_replace_string "\(\"ep_page_view_default\" *: \).*," "\1$pad_config_pageview," "$config_file" + ynh_app_setting_set $app pad_config_pageview "$pad_config_pageview" restart_etherpad=1 fi @@ -232,17 +258,23 @@ apply_config() { # Change public accessibility if [ "$is_public" = "true" ] then - is_public=1 + yunohost app action run $app public_private --args is_public=1 else - is_public=0 + yunohost app action run $app public_private --args is_public=0 fi - if [ $is_public -eq 1 ]; then - ynh_app_setting_set $app skipped_uris "/" - else - ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO... - fi - ynh_app_setting_set $app is_public $is_public - yunohost app ssowatconf + + # Set overwrite_settings + overwrite_settings=$(bool_to_01 $overwrite_settings) + ynh_app_setting_set $app overwrite_settings "$overwrite_settings" + # Set overwrite_credentials + overwrite_credentials=$(bool_to_01 $overwrite_credentials) + ynh_app_setting_set $app overwrite_credentials "$overwrite_credentials" + # 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" } #================================================= diff --git a/scripts/install b/scripts/install index 693dc65..0c6e497 100644 --- a/scripts/install +++ b/scripts/install @@ -72,6 +72,10 @@ ynh_app_setting_set $app language $language ynh_app_setting_set $app export $export ynh_app_setting_set $app mypads $mypads ynh_app_setting_set $app useldap $useldap +ynh_app_setting_set $app overwrite_settings "1" +ynh_app_setting_set $app overwrite_credentials "1" +ynh_app_setting_set $app overwrite_nginx "1" +ynh_app_setting_set $app overwrite_systemd "1" #================================================= # ACTIVATE MAINTENANCE MODE diff --git a/scripts/upgrade b/scripts/upgrade index 0df9520..c4b8330 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -28,6 +28,17 @@ export=$(ynh_app_setting_get $app export) db_name=$(ynh_app_setting_get $app db_name) mypads=$(ynh_app_setting_get $app mypads) useldap=$(ynh_app_setting_get $app useldap) +overwrite_settings=$(ynh_app_setting_get $app overwrite_settings) +overwrite_credentials=$(ynh_app_setting_get $app overwrite_credentials) +overwrite_nginx=$(ynh_app_setting_get $app overwrite_nginx) +overwrite_systemd=$(ynh_app_setting_get $app overwrite_systemd) + +# Optional parameters from config-panel feature +pad_config_nocolors=$(ynh_app_setting_get $app pad_config_nocolors) +pad_config_showlinenumbers=$(ynh_app_setting_get $app pad_config_showlinenumbers) +pad_config_chatandusers=$(ynh_app_setting_get $app pad_config_chatandusers) +pad_config_alwaysshowchat=$(ynh_app_setting_get $app pad_config_alwaysshowchat) +pad_config_show_markdown=$(ynh_app_setting_get $app pad_config_show_markdown) #================================================= # CHECK VERSION @@ -39,7 +50,7 @@ ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/eth ynh_abort_if_up_to_date #================================================= -# FIX OLD THINGS +# ENSURE DOWNWARD COMPATIBILITY #================================================= if [ "$is_public" = "Yes" ]; then @@ -50,17 +61,17 @@ elif [ "$is_public" = "No" ]; then is_public=0 fi -if [ -z $db_name ]; then # If db_name setting doesn't exist +if [ -z "$db_name" ]; then # If db_name setting doesn't exist db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name fi -if [ -z $abiword ]; then # If abiword setting doesn't exist +if [ -z "$abiword" ]; then # If abiword setting doesn't exist abiword=0 ynh_app_setting_set $app abiword $abiword fi -if [ -n $abiword ]; then # If abiword setting exists +if [ -n "$abiword" ]; then # If abiword setting exists if [ $abiword -eq 1 ]; then export=abiword fi @@ -68,26 +79,50 @@ if [ -n $abiword ]; then # If abiword setting exists ynh_app_setting_delete $app abiword fi -if [ -z $export ]; then # If export setting doesn't exist +if [ -z "$export" ]; then # If export setting doesn't exist export=none ynh_app_setting_set $app export $export fi -if [ -z $mypads ]; then # If mypads setting doesn't exist +if [ -z "$mypads" ]; then # If mypads setting doesn't exist mypads=1 ynh_app_setting_set $app mypads $mypads fi -if [ -z $useldap ]; then # If useldap setting doesn't exist +if [ -z "$useldap" ]; then # If useldap setting doesn't exist useldap=0 ynh_app_setting_set $app useldap $useldap fi -if [ -z $path_url ]; then # If path_url setting doesn't exist +if [ -z "$path_url" ]; then # If path_url setting doesn't exist path_url="/" ynh_app_setting_set $app path $path_url fi +# If overwrite_settings doesn't exist, create it +if [ -z "$overwrite_settings" ]; then + overwrite_settings=1 + ynh_app_setting_set $app overwrite_settings $overwrite_settings +fi + +# If overwrite_credentials doesn't exist, create it +if [ -z "$overwrite_credentials" ]; then + overwrite_credentials=1 + ynh_app_setting_set $app overwrite_credentials $overwrite_credentials +fi + +# If overwrite_nginx doesn't exist, create it +if [ -z "$overwrite_nginx" ]; then + overwrite_nginx=1 + ynh_app_setting_set $app overwrite_nginx $overwrite_nginx +fi + +# If overwrite_systemd doesn't exist, create it +if [ -z "$overwrite_systemd" ]; then + overwrite_systemd=1 + ynh_app_setting_set $app overwrite_systemd $overwrite_systemd +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -128,12 +163,16 @@ ynh_setup_source "$final_path" # Download, check integrity and uncompress the so # NGINX CONFIGURATION #================================================= -if [ "$path_url" != "/" ] +# Overwrite the nginx configuration only if it's allowed +if [ $overwrite_nginx -eq 1 ] then - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" + if [ "$path_url" != "/" ] + then + ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" + fi + ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" + ynh_add_nginx_config fi -ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" -ynh_add_nginx_config #================================================= # UPGRADE NODEJS @@ -172,40 +211,66 @@ done <<< "$(ls -1 "$final_path/node_modules" | grep "^ep_")") # CONFIGURE ETHERPAD #================================================= -ynh_backup_if_checksum_is_different "$final_path/settings.json" # Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "$final_path/credentials.json" # Verify the checksum and backup the file if it's different -cp ../conf/settings.json "$final_path/settings.json" -cp ../conf/credentials.json "$final_path/credentials.json" -ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" -ynh_replace_string "__DB_USER__" "$app" "$final_path/credentials.json" -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON -ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" -ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" -ynh_print_OFF; ynh_replace_special_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON -if [ "$export" = "abiword" ] +# Overwrite the settings config file only if it's allowed +if [ $overwrite_settings -eq 1 ] then - abiword_path=`which abiword` # Get abiword binary path - ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad -elif [ "$export" = "libreoffice" ] -then - soffice_path=`which soffice` # Get soffice binary path - ynh_replace_string "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad -fi -if test -z $language; then - language=en # If upgrading from a version which doesn't support translations, set language to English by default - ynh_app_setting_set $app language $language -fi -ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" + ynh_backup_if_checksum_is_different "$final_path/settings.json" # Verify the checksum and backup the file if it's different + cp ../conf/settings.json "$final_path/settings.json" + ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" + if [ "$export" = "abiword" ] + then + abiword_path=`which abiword` # Get abiword binary path + ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad + elif [ "$export" = "libreoffice" ] + then + soffice_path=`which soffice` # Get soffice binary path + ynh_replace_string "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad + fi + if test -z $language; then + language=en # If upgrading from a version which doesn't support translations, set language to English by default + ynh_app_setting_set $app language $language + fi + ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" + # Use ldap for mypads + if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] + then + ynh_replace_string "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json" + fi -# Use ldap for mypads -if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] -then - ynh_replace_string "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json" + # Optional parameters from config-panel feature + if [ -n "$pad_config_nocolors" ]; then + ynh_replace_string "\(\"noColors\" *: \).*," "\1$pad_config_nocolors," "$final_path/settings.json" + fi + if [ -n "$pad_config_showlinenumbers" ]; then + ynh_replace_string "\(\"showLineNumbers\" *: \).*," "\1$pad_config_showlinenumbers," "$final_path/settings.json" + fi + if [ -n "$pad_config_chatandusers" ]; then + ynh_replace_string "\(\"chatAndUsers\" *: \).*," "\1$pad_config_chatandusers," "$final_path/settings.json" + fi + if [ -n "$pad_config_alwaysshowchat" ]; then + ynh_replace_string "\(\"alwaysShowChat\" *: \).*," "\1$pad_config_alwaysshowchat," "$final_path/settings.json" + fi + if [ -n "$pad_config_show_markdown" ]; then + ynh_replace_string "\(\"ep_markdown_default\" *: \).*," "\1$pad_config_show_markdown," "$final_path/settings.json" + fi + + ynh_store_file_checksum "$final_path/settings.json" # Recalculate and store the config file checksum into the app settings fi -ynh_store_file_checksum "$final_path/settings.json" # Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/credentials.json" # Recalculate and store the config file checksum into the app settings +# Overwrite the credentials config file only if it's allowed +if [ $overwrite_credentials -eq 1 ] +then + ynh_backup_if_checksum_is_different "$final_path/credentials.json" # Verify the checksum and backup the file if it's different + cp ../conf/credentials.json "$final_path/credentials.json" + ynh_replace_string "__DB_USER__" "$app" "$final_path/credentials.json" + db_pwd=$(ynh_app_setting_get $app mysqlpwd) + ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON + ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" + ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" + ynh_print_OFF; ynh_replace_special_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON + + ynh_store_file_checksum "$final_path/credentials.json" # Recalculate and store the config file checksum into the app settings +fi #================================================= # CREATE DEDICATED USER @@ -238,8 +303,12 @@ ynh_use_logrotate --non-append # SETUP SYSTEMD #================================================= -ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" -ynh_add_systemd_config +# Overwrite the systemd configuration only if it's allowed +if [ $overwrite_systemd -eq 1 ] +then + ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" + ynh_add_systemd_config +fi #================================================= # SOME HACKS