From f1c517ef341d867437c01217e83f08bf2cc7cdd7 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 11 Dec 2023 00:52:20 +0100 Subject: [PATCH] Simplify ynh_replace_string madness to handle configuration --- conf/settings.json | 50 ++++++++++++------------- scripts/install | 26 ++++++------- scripts/upgrade | 91 ++++++++++++++-------------------------------- 3 files changed, 64 insertions(+), 103 deletions(-) diff --git a/conf/settings.json b/conf/settings.json index baf5fc3..99f4736 100644 --- a/conf/settings.json +++ b/conf/settings.json @@ -246,29 +246,29 @@ "highlightSelectedText": false }, // ep_mypads -//noldap "ep_mypads": { -//noldap "ldap": { -//noldap // Your LDAP URL -//noldap "url": "ldap://127.0.0.1", -//noldap // Where to search your users -//noldap "searchBase": "ou=users,dc=yunohost,dc=org", -//noldap // A LDAP filter ({{username}} is replaced by user's login) -//noldap "searchFilter": "(&(|(objectclass=posixAccount))(uid={{username}}))", -//noldap // LDAP properties mapping for MyPads -//noldap "properties": { -//noldap // Which LDAP property will be used as user's login? -//noldap "login": "uid", -//noldap // as user's email -//noldap "email": "mail", -//noldap // as user's firstname -//noldap "firstname": "givenName", -//noldap // as users's lastname -//noldap "lastname": "sn" -//noldap }, -//noldap // Default langage for LDAP created users -//noldap "defaultLang": "__LANGUAGE__" -//noldap } -//noldap }, +__COMMENT_IF_LDAP_DISABLED__ "ep_mypads": { +__COMMENT_IF_LDAP_DISABLED__ "ldap": { +__COMMENT_IF_LDAP_DISABLED__ // Your LDAP URL +__COMMENT_IF_LDAP_DISABLED__ "url": "ldap://127.0.0.1", +__COMMENT_IF_LDAP_DISABLED__ // Where to search your users +__COMMENT_IF_LDAP_DISABLED__ "searchBase": "ou=users,dc=yunohost,dc=org", +__COMMENT_IF_LDAP_DISABLED__ // A LDAP filter ({{username}} is replaced by user's login) +__COMMENT_IF_LDAP_DISABLED__ "searchFilter": "(&(|(objectclass=posixAccount))(uid={{username}}))", +__COMMENT_IF_LDAP_DISABLED__ // LDAP properties mapping for MyPads +__COMMENT_IF_LDAP_DISABLED__ "properties": { +__COMMENT_IF_LDAP_DISABLED__ // Which LDAP property will be used as user's login? +__COMMENT_IF_LDAP_DISABLED__ "login": "uid", +__COMMENT_IF_LDAP_DISABLED__ // as user's email +__COMMENT_IF_LDAP_DISABLED__ "email": "mail", +__COMMENT_IF_LDAP_DISABLED__ // as user's firstname +__COMMENT_IF_LDAP_DISABLED__ "firstname": "givenName", +__COMMENT_IF_LDAP_DISABLED__ // as users's lastname +__COMMENT_IF_LDAP_DISABLED__ "lastname": "sn" +__COMMENT_IF_LDAP_DISABLED__ }, +__COMMENT_IF_LDAP_DISABLED__ // Default langage for LDAP created users +__COMMENT_IF_LDAP_DISABLED__ "defaultLang": "__LANGUAGE__" +__COMMENT_IF_LDAP_DISABLED__ } +__COMMENT_IF_LDAP_DISABLED__ }, /* * Should we suppress errors from being visible in the default Pad Text? @@ -312,7 +312,7 @@ * it to null disables Abiword and will only allow plain text and HTML * import/exports. */ - "abiword" : null, + "abiword" : __ABIWORD_PATH__, /* * This is the absolute path to the soffice executable. @@ -320,7 +320,7 @@ * LibreOffice can be used in lieu of Abiword to export pads. * Setting it to null disables LibreOffice exporting. */ - "soffice" : null, + "soffice" : __SOFFICE_PATH__, /* * Path to the Tidy executable. diff --git a/scripts/install b/scripts/install index 58912c2..ce29600 100644 --- a/scripts/install +++ b/scripts/install @@ -73,34 +73,30 @@ chown $app -R /var/log/$app #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=6 +ynh_script_progression --message="Configure etherpad..." -ynh_add_config --template="../conf/settings.json" --destination="$install_dir/settings.json" +abiword_path="null" +soffice_path="null" -if [ "$export" = "abiword" ] +if [[ "$export" == "abiword" ]] then - # Get Abiword binary path - abiword_path=`which abiword` - # Set the path of abiword into Etherpad config - ynh_replace_string --match_string="\"abiword\" : null" --replace_string="\"abiword\" : \"$abiword_path\"" --target_file="$install_dir/settings.json" -elif [ "$export" = "libreoffice" ] + abiword_path="\"$(which abiword)\"" +elif [[ "$export" == "libreoffice" ]] then - # Get soffice binary path - soffice_path=`which soffice` - # Set the path of soffice into Etherpad config - ynh_replace_string --match_string="\"soffice\" : null" --replace_string="\"soffice\" : \"$soffice_path\"" --target_file="$install_dir/settings.json" + soffice_path="\"$(which soffice)\"" fi # Use ldap for mypads +comment_if_ldap_disabled="//ldap_disabled" if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] then - ynh_replace_string --match_string="//noldap\(.*\)" --replace_string="\1 //useldap" --target_file="$install_dir/settings.json" + comment_if_ldap_disabled="" fi # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$install_dir/settings.json" -ynh_add_config --template="../conf/credentials.json" --destination="$install_dir/credentials.json" +ynh_add_config --template="settings.json" --destination="$install_dir/settings.json" +ynh_add_config --template="credentials.json" --destination="$install_dir/credentials.json" chmod 600 "$install_dir/settings.json" chown $app:$app "$install_dir/settings.json" diff --git a/scripts/upgrade b/scripts/upgrade index 0d41435..c92b8cb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -77,6 +77,12 @@ if [ -n "${abiword:-}" ]; then ynh_app_setting_delete --app=$app --key=abiword fi +if [ -z "${language:-}" ]; then + # If upgrading from a version which doesn't support translations, set language to English by default + language=en + ynh_app_setting_set --app=$app --key=language --value=$language +fi + # If export setting doesn't exist if [ -z "${export:-}" ]; then export=none @@ -177,72 +183,31 @@ chown $app -R /var/log/$app # CONFIGURE ETHERPAD #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] +ynh_script_progression --message="Configure etherpad..." + +abiword_path="null" +soffice_path="null" + +if [[ "$export" == "abiword" ]] then - ynh_script_progression --message="Reconfiguring Etherpad..." --weight=3 - - # Overwrite the settings config file only if it's allowed - if [ $overwrite_settings -eq 1 ] - then - # Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. - ynh_backup_if_checksum_is_different --file="$install_dir/settings.json" - - ynh_add_config --template="../conf/settings.json" --destination="$install_dir/settings.json" - - if [ "$export" = "abiword" ] - then - # Get abiword binary path - abiword_path=`which abiword` - # Set the path of Abiword into Etherpad config - ynh_replace_string --match_string="\"abiword\" : null" --replace_string="\"abiword\" : \"$abiword_path\"" --target_file="$install_dir/settings.json" - elif [ "$export" = "libreoffice" ] - then - # Get soffice binary path - soffice_path=`which soffice` - # Set the path of soffice into Etherpad config - ynh_replace_string --match_string="\"soffice\" : null" --replace_string="\"soffice\" : \"$soffice_path\"" --target_file="$install_dir/settings.json" - fi - - if test -z "$language"; then - # If upgrading from a version which doesn't support translations, set language to English by default - language=en - ynh_app_setting_set --app=$app --key=language --value=$language - fi - - # Use LDAP for MyPads - if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] - then - ynh_replace_string --match_string="//noldap" --replace_string="" --target_file="$install_dir/settings.json" - fi - - # Optional parameters from config-panel feature - if [ -n "$pad_config_nocolors" ]; then - ynh_replace_string --match_string="\(\"noColors\" *: \).*," --replace_string="\1$pad_config_nocolors," --target_file="$install_dir/settings.json" - fi - if [ -n "$pad_config_showlinenumbers" ]; then - ynh_replace_string --match_string="\(\"showLineNumbers\" *: \).*," --replace_string="\1$pad_config_showlinenumbers," --target_file="$install_dir/settings.json" - fi - if [ -n "$pad_config_chatandusers" ]; then - ynh_replace_string --match_string="\(\"chatAndUsers\" *: \).*," --replace_string="\1$pad_config_chatandusers," --target_file="$install_dir/settings.json" - fi - if [ -n "$pad_config_alwaysshowchat" ]; then - ynh_replace_string --match_string="\(\"alwaysShowChat\" *: \).*," --replace_string="\1$pad_config_alwaysshowchat," --target_file="$install_dir/settings.json" - fi - if [ -n "$pad_config_show_markdown" ]; then - ynh_replace_string --match_string="\(\"ep_markdown_default\" *: \).*," --replace_string="\1$pad_config_show_markdown," --target_file="$install_dir/settings.json" - fi - - # Recalculate and store the checksum of the file for the next upgrade. - ynh_store_file_checksum --file="$install_dir/settings.json" - fi - - # Overwrite the credentials config file only if it's allowed - if [ $overwrite_credentials -eq 1 ] - then - ynh_add_config --template="../conf/credentials.json" --destination="$install_dir/credentials.json" - fi + abiword_path="\"$(which abiword)\"" +elif [[ "$export" == "libreoffice" ]] +then + soffice_path="\"$(which soffice)\"" fi +# Use ldap for mypads +comment_if_ldap_disabled="//ldap_disabled" +if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] +then + comment_if_ldap_disabled="" +fi + +# Calculate and store the config file checksum into the app settings + +ynh_add_config --template="settings.json" --destination="$install_dir/settings.json" +ynh_add_config --template="credentials.json" --destination="$install_dir/credentials.json" + chmod 600 "$install_dir/settings.json" chown $app:$app "$install_dir/settings.json"