1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/snserver_ynh.git synced 2024-09-03 20:26:22 +02:00

Add app actions

This commit is contained in:
Fabian Wilkens 2021-01-16 23:04:32 +01:00
parent 661a6df212
commit d7857aa412
9 changed files with 224 additions and 31 deletions

10
actions.toml Normal file
View file

@ -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"

View file

@ -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__

View file

@ -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

View file

@ -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

View file

@ -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
@ -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'

View file

@ -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
#=================================================

View file

@ -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
@ -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'