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

115 lines
4 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
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)
access_domain=$(ynh_app_setting_get --app=$app --key=access_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. Please upgrade snserver" --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
ynh_replace_string --match_string="__DOMAIN__PATH__" --replace_string="$domain$path" --target_file="$final_path/live/public/extensions/repo.json"
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
#=================================================
# WAITING FOR SERVICE
#=================================================
ynh_script_progression --message="Waiting for service..." --weight=1
is_service_ready
#=================================================
# CONFIG INFORMATION
#=================================================
ynh_script_progression --message="Configuration Informations" --weight=1
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
ynh_print_info "You need to set the access_domain in the <a href=\"$admin_panel/config-panel\">config-panel</a> to be able to access the extentions via the Standard Notes web app."
ynh_print_info "access_domain is currently set to: $(echo $access_domain | sed "s@;@ @g")"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last