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

Upgrade actions and config-panel scripts

This commit is contained in:
maniack 2019-12-07 23:28:28 +01:00
parent 09190a0239
commit 7b19a35da5
7 changed files with 121 additions and 82 deletions

View file

@ -22,24 +22,6 @@ 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"
}
#=================================================
# FUTUR OFFICIAL HELPERS
#=================================================

View file

@ -29,14 +29,18 @@ then
# abiword is already a dependence of etherpad_mypads.
# abiword should be removed.
abiword=0
ynh_print_info "Abiword will be removed." >&2
action1=installed
action2=Installing
else
# abiword isn't a dependence of etherpad_mypads.
# abiword should be installed.
ynh_print_info "Abiword will be installed." >&2
abiword=1
action1=removed
action2=Removing
fi
ynh_print_info --message="Abiword will be $action1."
if apt-cache depends ${app//_/-}-ynh-deps | grep --quiet libreoffice-writer
then
# libreoffice is already a dependence of etherpad_mypads.
@ -54,6 +58,8 @@ fi
# INSTALL OR REMOVE ABIWORD
#=================================================
ynh_script_progression --message="$action2 Abiword..." --weight=3
# Load common variables, and especially abiword dependencies.
source scripts/_variables
@ -92,3 +98,9 @@ else
# Remove any export app
yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=none"
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -29,14 +29,18 @@ then
# libreoffice is already a dependence of etherpad_mypads.
# libreoffice should be removed.
libreoffice=0
ynh_print_info "Libreoffice writer will be removed." >&2
action1=installed
action2=Installing
else
# libreoffice isn't a dependence of etherpad_mypads.
# libreoffice should be installed.
ynh_print_info "Libreoffice writer will be installed." >&2
libreoffice=1
action1=removed
action2=Removing
fi
ynh_print_info --message="Libreoffice will be $action1."
if apt-cache depends ${app//_/-}-ynh-deps | grep --quiet abiword
then
# abiword is already a dependence of etherpad_mypads.
@ -54,6 +58,8 @@ fi
# INSTALL OR REMOVE LIBREOFFICE
#=================================================
ynh_script_progression --message="$action2 Libreoffice..." --weight=3
# Load common variables, and especially libreoffice dependencies.
source scripts/_variables
@ -92,3 +98,9 @@ else
# Remove any export app
yunohost app config apply $app -a "YNH_CONFIG_MAIN_EXPORT_EXPORT=none"
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -15,8 +15,8 @@ source /usr/share/yunohost/helpers
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)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
@ -32,4 +32,12 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd)
# LIST ALL PADS FROM THE DATABASE
#=================================================
ynh_script_progression --message="Listing all pads..." --weight=3
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
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -25,11 +25,11 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
is_public_old=$(ynh_app_setting_get $app is_public)
is_public_old=$(ynh_app_setting_get --app=$app --key=is_public)
if [ $is_public -eq $is_public_old ]
then
ynh_die "is_public is already set as $is_public." 0
ynh_die --message="is_public is already set as $is_public." --ret_code=0
fi
#=================================================
@ -38,21 +38,36 @@ fi
# MOVE TO PUBLIC OR PRIVATE
#=================================================
if [ $is_public -eq 0 ]; then
public_private="private"
else
public_private="public"
fi
ynh_script_progression --message="Moving the application to $public_private..." --weight=3
if [ $is_public -eq 0 ]
then
ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO...
ynh_app_setting_set --app=$app --key=skipped_uris --value="/admin" # etherpad admin page doesn't support SSO...
else
ynh_app_setting_set $app skipped_uris "/"
ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
fi
ynh_script_progression --message="Upgrading SSOwat configuration..."
# Regen ssowat configuration
yunohost app ssowatconf
# Update the config of the app
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
systemctl reload nginx
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -14,12 +14,13 @@ source /usr/share/yunohost/helpers
#=================================================
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)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
export=$(ynh_app_setting_get --app=$app --key=export)
language=$(ynh_app_setting_get --app=$app --key=language)
mypads=$(ynh_app_setting_get --app=$app --key=mypads)
useldap=$(ynh_app_setting_get --app=$app --key=useldap)
#=================================================
# SORT OUT THE CONFIG FILE TO HANDLE
@ -36,9 +37,10 @@ fi
#=================================================
# RESET THE CONFIG FILE
#=================================================
ynh_script_progression --message="Resetting the config file $config_file..." --weight=3
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$config_file"
ynh_backup_if_checksum_is_different --file="$config_file"
if [ "$file" = "settings.json" ]
then
@ -46,27 +48,38 @@ then
cp /etc/yunohost/apps/$app/conf/settings.json "$config_file"
# Recreate the default config
ynh_replace_string "__PORT__" "$port" "$final_path/settings.json"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$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
ynh_replace_string --match_string="\"abiword\" : null" --replace_string="\"abiword\" : \"$abiword_path\"" --target_file="$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
ynh_replace_string --match_string="\"soffice\" : null" --replace_string="\"soffice\" : \"$soffice_path\"" --target_file="$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad
fi
ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json"
ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$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"
ynh_replace_string --match_string="//noldap\(.*\)" --replace_string="\1 //useldap" --target_file="$final_path/settings.json"
fi
fi
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$config_file"
ynh_store_file_checksum --file="$config_file"
#=================================================
# CHECK ETHERPAD STARTING
#=================================================
ynh_script_progression --message="Restarting Etherpad..." --weight=9
# Wait for etherpad to be fully started
ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120"
ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last

View file

@ -50,18 +50,23 @@ 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}"
@ -74,6 +79,7 @@ else
old_mypads=false
fi
mypads="${YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_MYPADS:-$old_mypads}"
# Ldap for Mypads
if grep -q "//noldap" $config_file
then
@ -84,28 +90,23 @@ fi
useldap="${YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_USELDAP:-$old_useldap}"
# is_public
old_is_public="$(ynh_app_setting_get $app is_public)"
old_is_public=$(bool_to_true_false $old_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 overwrite_settings)"
old_overwrite_settings=$(bool_to_true_false $old_overwrite_settings)
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 overwrite_credentials)"
old_overwrite_credentials=$(bool_to_true_false $old_overwrite_credentials)
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 overwrite_nginx)"
old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
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 overwrite_systemd)"
old_overwrite_systemd=$(bool_to_true_false $old_overwrite_systemd)
old_overwrite_systemd="$(ynh_app_setting_get --app=$app --key=overwrite_systemd)"
overwrite_systemd="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SYSTEMD:-$old_overwrite_systemd}"
#=================================================
@ -147,48 +148,48 @@ apply_config() {
# padOptions noColors
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"
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 "\(\"showLineNumbers\" *: \).*," "\1$pad_config_showlinenumbers," "$config_file"
ynh_app_setting_set $app pad_config_showlinenumbers "$pad_config_showlinenumbers"
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 "\(\"chatAndUsers\" *: \).*," "\1$pad_config_chatandusers," "$config_file"
ynh_app_setting_set $app pad_config_chatandusers "$pad_config_chatandusers"
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 "\(\"alwaysShowChat\" *: \).*," "\1$pad_config_alwaysshowchat," "$config_file"
ynh_app_setting_set $app pad_config_alwaysshowchat "$pad_config_alwaysshowchat"
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 "\(\"ep_markdown_default\" *: \).*," "\1$pad_config_show_markdown," "$config_file"
ynh_app_setting_set $app pad_config_show_markdown "$pad_config_show_markdown"
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 "\(\"ep_page_view_default\" *: \).*," "\1$pad_config_pageview," "$config_file"
ynh_app_setting_set $app pad_config_pageview "$pad_config_pageview"
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
@ -202,8 +203,8 @@ apply_config() {
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"
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.
@ -211,11 +212,11 @@ apply_config() {
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"
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 "\(\"abiword\" *: \).*," "\1null," "$config_file"
ynh_replace_string "\(\"soffice\" *: \).*," "\1null," "$config_file"
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
@ -241,9 +242,9 @@ apply_config() {
then
if [ "$useldap" = "true" ]
then
ynh_replace_string "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json"
ynh_replace_string --match_string="//noldap\(.*\)" --replace_string="\1 //useldap" --target_file="$final_path/settings.json"
else
ynh_replace_string "\(.*\) //useldap" "//noldap\1" "$final_path/settings.json"
ynh_replace_string --match_string="\(.*\) //useldap" --replace_string="//noldap\1" --target_file="$final_path/settings.json"
fi
restart_etherpad=1
fi
@ -264,17 +265,13 @@ apply_config() {
fi
# Set overwrite_settings
overwrite_settings=$(bool_to_01 $overwrite_settings)
ynh_app_setting_set $app overwrite_settings "$overwrite_settings"
ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings"
# Set overwrite_credentials
overwrite_credentials=$(bool_to_01 $overwrite_credentials)
ynh_app_setting_set $app overwrite_credentials "$overwrite_credentials"
ynh_app_setting_set --app=$app --key=overwrite_credentials --value="$overwrite_credentials"
# Set overwrite_nginx
overwrite_nginx=$(bool_to_01 $overwrite_nginx)
ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx"
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
# Set overwrite_systemd
overwrite_systemd=$(bool_to_01 $overwrite_systemd)
ynh_app_setting_set $app overwrite_systemd "$overwrite_systemd"
ynh_app_setting_set --app=$app --key=overwrite_systemd --value="$overwrite_systemd"
}
#=================================================