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
2021-01-16 23:04:32 +01:00

94 lines
3 KiB
Bash

#!/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