diff --git a/actions.toml b/actions.toml new file mode 100644 index 0000000..0cc4fec --- /dev/null +++ b/actions.toml @@ -0,0 +1,10 @@ +[install_extensions] +name = "Install Extensions" +description = "Intall Standard Notes - Extensions" +command = "/bin/bash actions/install_extensions" +cwd = "/etc/yunohost/apps/$app/scripts" + +[remove_extensions] +name = "Remove Extensions" +description = "Remove Standard Notes - Extensions" +command = "/bin/bash scripts/actions/remove_extensions" diff --git a/check_process b/check_process index c8dd4a8..12e1e89 100644 --- a/check_process +++ b/check_process @@ -5,9 +5,9 @@ ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - is_public=1 (PUBLIC|public=1|private=0) + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + is_public=1 (PUBLIC|public=1|private=0) install_extensions=1 access_domain="/" ; Checks @@ -19,7 +19,7 @@ setup_public=1 upgrade=1 # 3.13.6~ynh1 - upgrade=1 from_commit=7474baadc1705ffe5981a52bdced16bdd1edf979 + upgrade=1 from_commit=7474baadc1705ffe5981a52bdced16bdd1edf979 backup_restore=1 multi_instance=1 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. diff --git a/conf/message b/conf/message index 8b5460d..d8a5625 100644 --- a/conf/message +++ b/conf/message @@ -1,4 +1,4 @@ -Standard Notes - syncing server was successfully __TYPE__. +Standard Notes - Syncing Server was successfully __TYPE__. Please configure the Standard Notes web app or mobile app to use this syninc server: https://__DOMAIN____PATH_URL__/ -__CONFIG_PANEL__ +__ACTION__ __EXTENSIONS__ diff --git a/manifest.json b/manifest.json index ef4c8c5..0317793 100644 --- a/manifest.json +++ b/manifest.json @@ -74,7 +74,7 @@ "ask": { "en": "Choose a domain which has access to the extensions. E.g. the Standard-Notes web app." }, - "optional": true, + "optional": true, "example": "example.tld", "default": "" } diff --git a/scripts/actions/install_extensions b/scripts/actions/install_extensions new file mode 100644 index 0000000..b512451 --- /dev/null +++ b/scripts/actions/install_extensions @@ -0,0 +1,94 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_INSTANCE_NAME +path_url=$(ynh_app_setting_get --app=$app --key=path) +domain=$(ynh_app_setting_get --app=$app --key=domain) + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +final_path=/opt/yunohost/$app +config_file="$final_path/live/.env" + +if [[ ! -f $config_file || \ + ! -d "$final_path/live/public/extensions/" || \ + ! -d "$final_path/live/public/extensions/src/" ]] +then + ynh_die --message="Standard Notes - Extensions can not be installed." --ret_code=1 +fi + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +install_extensions_old=$(ynh_app_setting_get --app=$app --key=install_extensions) + +if [ $install_extensions_old -eq 1 ] +then + ynh_die --message="Standard Notes - Extensions should alredy be installed." --ret_code=0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# MOVE TO PUBLIC OR PRIVATE +#================================================= + +ynh_script_progression --message="Installing Standard Notes - Extensions ..." --weight=5 + +ynh_replace_string --match_string="^RAILS_SERVE_STATIC_FILES=.*$" --replace_string="RAILS_SERVE_STATIC_FILES=true" --target_file="$config_file" + +if [ "$path_url" = "/" ] +then + path="" +else + path=$path_url +fi + +find "$final_path/live/public/extensions/src/" -name "*.json" -print0 | while read -d $'\0' file +do + ynh_replace_string --match_string="__DOMAIN__PATH__" --replace_string="$domain$path" --target_file="$file" +done + +find "../conf/" -name "ext_*.src" -print0 | while read -d $'\0' file +do + basename=$(basename -as .src $file) + ynh_setup_source --dest_dir="$final_path/live/public/extensions/src/${basename#'ext_'}" --source_id="$basename" + ynh_secure_remove --file="$basename.zip" +done + +# Update the config of the app +ynh_app_setting_set --app=$app --key=install_extensions --value="1" + +#================================================= +# RESTART Systemd +#================================================= +ynh_script_progression --message="Restarting $app ..." + +ynh_systemd_action --service_name=$app --action=restart + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Execution completed" --last diff --git a/scripts/actions/remove_extensions b/scripts/actions/remove_extensions new file mode 100644 index 0000000..afd7833 --- /dev/null +++ b/scripts/actions/remove_extensions @@ -0,0 +1,90 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_INSTANCE_NAME +path_url=$(ynh_app_setting_get --app=$app --key=path) +domain=$(ynh_app_setting_get --app=$app --key=domain) + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +final_path=/opt/yunohost/$app +config_file="$final_path/live/.env" + +if [ ! -f $config_file ] +then + ynh_die --message="Standard Notes - Extensions can not be removed." --ret_code=1 +fi + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +install_extensions_old=$(ynh_app_setting_get --app=$app --key=install_extensions) + +if [ $install_extensions_old -eq 0 ] +then + ynh_die --message="Standard Notes - Extensions should not be installed." --ret_code=0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# MOVE TO PUBLIC OR PRIVATE +#================================================= + +ynh_script_progression --message="Remove Standard Notes - Extensions ..." --weight=5 + +ynh_replace_string --match_string="^RAILS_SERVE_STATIC_FILES=.*$" --replace_string="RAILS_SERVE_STATIC_FILES=" --target_file="$config_file" + +if [ "$path_url" = "/" ] +then + path="" +else + path=$path_url +fi + +find "$final_path/live/public/extensions/src/" -name "*.json" -print0 | while read -d $'\0' file +do + ynh_replace_string --match_string="$domain$path" --replace_string="__DOMAIN__PATH__" --target_file="$file" +done + +find "$final_path/live/public/extensions/src/" -mindepth 1 -maxdepth 1 -type d -print0 | while read -d $'\0' dir +do + ynh_secure_remove --file="$dir" +done + +# Update the config of the app +ynh_app_setting_set --app=$app --key=install_extensions --value="0" + +#================================================= +# RESTART Systemd +#================================================= +ynh_script_progression --message="Restarting $app ..." + +ynh_systemd_action --service_name=$app --action=restart + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Execution completed" --last diff --git a/scripts/change_url b/scripts/change_url index 8aefeb4..1a6097f 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -119,7 +119,7 @@ ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=$old_path" --replace_ #================================================= # Modify Standard Notes - Extensions #================================================= -if [ $install_extensions ] +if [ $install_extensions -eq 1 ] then ynh_script_progression --message="Modify Standard Notes - Extensions..." --weight=1 @@ -146,9 +146,9 @@ path_url=$new_path # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" ynh_add_fail2ban_config --use_template --others_var="\ - domain \ - path_url \ - " + domain \ + path_url \ + " #================================================= # GENERIC FINALISATION @@ -174,21 +174,21 @@ ynh_script_progression --message="Sending a readme for the admin..." admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" -message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\ +message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\n\ You changed the url of the syncing server. All extensions installed from here must be reinstalled by the users." -config_panel="You can configure this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" +action="You can find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__" ynh_replace_string --match_string="__TYPE__" --replace_string="changed the url" --target_file="../conf/message" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" -if [ $install_extensions ] +if [ $install_extensions -eq 1 ] then ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_extensions" --target_file="../conf/message" else ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="" --target_file="../conf/message" fi -ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" +ynh_replace_string --match_string="__ACTION__" --replace_string="$action" --target_file="../conf/message" ynh_send_readme_to_admin --app_message="../conf/message" --type='upgrade' diff --git a/scripts/install b/scripts/install index 1060cb2..84e7f66 100755 --- a/scripts/install +++ b/scripts/install @@ -160,7 +160,7 @@ popd #================================================= # INSTALLING Standard Notes - Extensions #================================================= -if [ $install_extensions ] +if [ $install_extensions -eq 1 ] then ynh_script_progression --message="Installing Standard Notes - Extensions..." --weight=1 @@ -284,29 +284,28 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Sending a readme for the admin..." -message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\ +message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\n\ If you want to change the url of the syncing server all extensions from here have to be reinstalled be the users." -message_no_extensions="You have no extensions installed.\ +message_no_extensions="You have no extensions installed.\n\ You can configure this app by using the config-panel" admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" -config_panel="You can configure this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" +action="You can find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__" ynh_replace_string --match_string="__TYPE__" --replace_string="installed" --target_file="../conf/message" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" -if [ $install_extensions ] +if [ $install_extensions -eq 1 ] then ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_extensions" --target_file="../conf/message" else ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_no_extensions" --target_file="../conf/message" fi -ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" +ynh_replace_string --match_string="__ACTION__" --replace_string="$action" --target_file="../conf/message" ynh_send_readme_to_admin --app_message="../conf/message" --type='install' -echo ../conf/message #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 1ba1cf7..a224e23 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -188,7 +188,7 @@ fi #================================================= # INSTALLING Standard Notes - Extensions #================================================= -if [ $install_extensions ] +if [ $install_extensions -eq 1 ] then ynh_script_progression --message="Reinstalling Standard Notes - Extensions..." --weight=1 @@ -273,9 +273,9 @@ ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1 # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" ynh_add_fail2ban_config --use_template --others_var="\ - domain \ - path_url \ - " + domain \ + path_url \ + " #================================================= # SETUP SSOWAT @@ -311,25 +311,25 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Sending a readme for the admin..." -message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\ +message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\n\ If you want to change the url of the syncing server all extensions from here have to be reinstalled be the users." -message_no_extensions="You have no extensions installed.\ +message_no_extensions="You have no extensions installed.\n\ You can configure this app by using the config-panel" admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" -config_panel="You can configure this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" +action="You can find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__" ynh_replace_string --match_string="__TYPE__" --replace_string="installed" --target_file="../conf/message" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" -if [ $install_extensions ] +if [ $install_extensions -eq 1 ] then ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_extensions" --target_file="../conf/message" else ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_no_extensions" --target_file="../conf/message" fi -ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" +ynh_replace_string --match_string="__ACTION__" --replace_string="$action" --target_file="../conf/message" ynh_send_readme_to_admin --app_message="../conf/message" --type='upgrade'