1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git synced 2024-09-03 18:36:09 +02:00

Simplify ynh_replace_string madness to handle configuration

This commit is contained in:
Alexandre Aubin 2023-12-11 00:52:20 +01:00
parent 3b19355854
commit f1c517ef34
3 changed files with 64 additions and 103 deletions

View file

@ -246,29 +246,29 @@
"highlightSelectedText": false "highlightSelectedText": false
}, },
// ep_mypads // ep_mypads
//noldap "ep_mypads": { __COMMENT_IF_LDAP_DISABLED__ "ep_mypads": {
//noldap "ldap": { __COMMENT_IF_LDAP_DISABLED__ "ldap": {
//noldap // Your LDAP URL __COMMENT_IF_LDAP_DISABLED__ // Your LDAP URL
//noldap "url": "ldap://127.0.0.1", __COMMENT_IF_LDAP_DISABLED__ "url": "ldap://127.0.0.1",
//noldap // Where to search your users __COMMENT_IF_LDAP_DISABLED__ // Where to search your users
//noldap "searchBase": "ou=users,dc=yunohost,dc=org", __COMMENT_IF_LDAP_DISABLED__ "searchBase": "ou=users,dc=yunohost,dc=org",
//noldap // A LDAP filter ({{username}} is replaced by user's login) __COMMENT_IF_LDAP_DISABLED__ // A LDAP filter ({{username}} is replaced by user's login)
//noldap "searchFilter": "(&(|(objectclass=posixAccount))(uid={{username}}))", __COMMENT_IF_LDAP_DISABLED__ "searchFilter": "(&(|(objectclass=posixAccount))(uid={{username}}))",
//noldap // LDAP properties mapping for MyPads __COMMENT_IF_LDAP_DISABLED__ // LDAP properties mapping for MyPads
//noldap "properties": { __COMMENT_IF_LDAP_DISABLED__ "properties": {
//noldap // Which LDAP property will be used as user's login? __COMMENT_IF_LDAP_DISABLED__ // Which LDAP property will be used as user's login?
//noldap "login": "uid", __COMMENT_IF_LDAP_DISABLED__ "login": "uid",
//noldap // as user's email __COMMENT_IF_LDAP_DISABLED__ // as user's email
//noldap "email": "mail", __COMMENT_IF_LDAP_DISABLED__ "email": "mail",
//noldap // as user's firstname __COMMENT_IF_LDAP_DISABLED__ // as user's firstname
//noldap "firstname": "givenName", __COMMENT_IF_LDAP_DISABLED__ "firstname": "givenName",
//noldap // as users's lastname __COMMENT_IF_LDAP_DISABLED__ // as users's lastname
//noldap "lastname": "sn" __COMMENT_IF_LDAP_DISABLED__ "lastname": "sn"
//noldap }, __COMMENT_IF_LDAP_DISABLED__ },
//noldap // Default langage for LDAP created users __COMMENT_IF_LDAP_DISABLED__ // Default langage for LDAP created users
//noldap "defaultLang": "__LANGUAGE__" __COMMENT_IF_LDAP_DISABLED__ "defaultLang": "__LANGUAGE__"
//noldap } __COMMENT_IF_LDAP_DISABLED__ }
//noldap }, __COMMENT_IF_LDAP_DISABLED__ },
/* /*
* Should we suppress errors from being visible in the default Pad Text? * 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 * it to null disables Abiword and will only allow plain text and HTML
* import/exports. * import/exports.
*/ */
"abiword" : null, "abiword" : __ABIWORD_PATH__,
/* /*
* This is the absolute path to the soffice executable. * This is the absolute path to the soffice executable.
@ -320,7 +320,7 @@
* LibreOffice can be used in lieu of Abiword to export pads. * LibreOffice can be used in lieu of Abiword to export pads.
* Setting it to null disables LibreOffice exporting. * Setting it to null disables LibreOffice exporting.
*/ */
"soffice" : null, "soffice" : __SOFFICE_PATH__,
/* /*
* Path to the Tidy executable. * Path to the Tidy executable.

View file

@ -73,34 +73,30 @@ chown $app -R /var/log/$app
#================================================= #=================================================
# ADD A CONFIGURATION # 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 then
# Get Abiword binary path abiword_path="\"$(which abiword)\""
abiword_path=`which abiword` elif [[ "$export" == "libreoffice" ]]
# 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 then
# Get soffice binary path soffice_path="\"$(which soffice)\""
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 fi
# Use ldap for mypads # Use ldap for mypads
comment_if_ldap_disabled="//ldap_disabled"
if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] if [ $mypads -eq 1 ] && [ $useldap -eq 1 ]
then then
ynh_replace_string --match_string="//noldap\(.*\)" --replace_string="\1 //useldap" --target_file="$install_dir/settings.json" comment_if_ldap_disabled=""
fi fi
# Calculate and store the config file checksum into the app settings # 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" chmod 600 "$install_dir/settings.json"
chown $app:$app "$install_dir/settings.json" chown $app:$app "$install_dir/settings.json"

View file

@ -77,6 +77,12 @@ if [ -n "${abiword:-}" ]; then
ynh_app_setting_delete --app=$app --key=abiword ynh_app_setting_delete --app=$app --key=abiword
fi 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 export setting doesn't exist
if [ -z "${export:-}" ]; then if [ -z "${export:-}" ]; then
export=none export=none
@ -177,72 +183,31 @@ chown $app -R /var/log/$app
# CONFIGURE ETHERPAD # CONFIGURE ETHERPAD
#================================================= #=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] ynh_script_progression --message="Configure etherpad..."
abiword_path="null"
soffice_path="null"
if [[ "$export" == "abiword" ]]
then then
ynh_script_progression --message="Reconfiguring Etherpad..." --weight=3 abiword_path="\"$(which abiword)\""
elif [[ "$export" == "libreoffice" ]]
# Overwrite the settings config file only if it's allowed then
if [ $overwrite_settings -eq 1 ] soffice_path="\"$(which soffice)\""
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
fi 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" chmod 600 "$install_dir/settings.json"
chown $app:$app "$install_dir/settings.json" chown $app:$app "$install_dir/settings.json"