1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nodered_ynh.git synced 2024-09-03 19:46:25 +02:00
nodered_ynh/scripts/upgrade

191 lines
6.4 KiB
Text
Raw Normal View History

2019-05-29 00:20:58 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2019-10-13 19:50:59 +02:00
source ynh_exec_as
2019-05-29 00:20:58 +02:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2019-05-29 00:20:58 +02:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
port=$(ynh_app_setting_get --app=$app --key=port)
2019-05-29 00:20:58 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2019-05-29 00:20:58 +02:00
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2019-05-29 00:20:58 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2019-05-29 00:20:58 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs $nodejs_version
2019-05-29 00:20:58 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2019-05-29 00:20:58 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
2019-10-13 19:50:59 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2019-10-13 19:50:59 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# Install through npm
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Installing node-red..." --weight=30
2019-10-13 19:50:59 +02:00
chown -R $app: $final_path
pushd $final_path
ynh_use_nodejs
2019-10-13 19:50:59 +02:00
exec_as $app env PATH=$PATH npm install --production
popd
2019-05-29 00:20:58 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
2019-05-29 00:20:58 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
if [ ! -f $final_path/data/settings.js ]; then
cp $final_path/settings.js $final_path/data/settings.js
fi
2020-08-29 15:56:43 +02:00
ynh_replace_string --match_string="//httpRoot: '/red'," --replace_string="httpRoot: '$path_url'," --target_file="$final_path/data/settings.js"
ynh_replace_string --match_string="//ui: { path: "ui" }," --replace_string="ui: { path: "/ui/" }," --target_file="$final_path/data/settings.js"
2019-05-29 00:20:58 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2019-05-29 00:20:58 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# SETUP SYSTEMD
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
2019-05-29 00:20:58 +02:00
# Set the systemd service settings
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_replace_string "__NODEJS__" "$nodejs_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
2019-05-29 00:20:58 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R $app: $final_path
2019-05-29 00:20:58 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
2019-05-29 00:20:58 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2019-05-29 00:20:58 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Reloading nginx web server..." --weight=1
2019-05-29 00:20:58 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last