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

212 lines
6.8 KiB
Text
Raw Normal View History

2019-05-29 00:20:58 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
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)
port=$(ynh_app_setting_get --app=$app --key=port)
if [[ $path_url = "/" ]]
2021-05-23 15:45:29 +02:00
then
nodes_url="/"
admin_url="/admin"
2021-05-23 15:45:29 +02:00
else
nodes_url="$path_url"
admin_url="$path_url/admin"
2021-05-23 15:45:29 +02:00
fi
2019-05-29 00:20:58 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
2021-05-23 15:45:29 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up Node-RED before upgrading (may take a while)..." --weight=1
# 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
2019-05-29 00:20:58 +02:00
#=================================================
# 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
# 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
2021-02-14 14:08:08 +01:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
2021-05-23 15:45:29 +02:00
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --label="admin" --show_tile=true
2021-05-23 15:45:29 +02:00
fi
2019-05-29 00:20:58 +02:00
if ynh_permission_exists --permission="ui"; then
# Delete the old permission
ynh_permission_delete --permission="ui"
fi
2020-11-07 19:49:00 +01:00
#=================================================
# CLOSING PORT
#=================================================
# In older versions of the package, the port serving the webui was opened to anyone,
# allowing direct access to Node-RED... let's close it.
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
2019-05-29 00:20:58 +02:00
#=================================================
# 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"
2019-05-29 00:20:58 +02:00
#=================================================
# INSTALL NODEJS
#=================================================
if [ $(ynh_app_setting_get --app=$app --key=nodejs_version) != $nodejs_version ]; then
ynh_remove_nodejs
ynh_install_nodejs --nodejs_version=$nodejs_version
fi
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
#=================================================
ynh_script_progression --message="Installing Node-RED..." --weight=30
2021-05-25 10:41:05 +02:00
ynh_use_nodejs
chown -R $app: "$final_path"
pushd $final_path
2021-07-20 22:12:24 +02:00
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install --production
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install node-red-dashboard
popd
2019-05-29 00:20:58 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
2019-05-29 00:20:58 +02:00
# Create a dedicated NGINX config
2019-05-29 00:20:58 +02:00
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
2021-05-23 15:45:29 +02:00
# Set up the settings file
ynh_add_config --template="../conf/settings.js" --destination="$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
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
2021-06-07 23:13:39 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app: "$final_path"
2019-05-29 00:20:58 +02:00
2020-12-07 09:50:58 +01:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
2021-01-08 23:12:27 +01:00
yunohost service add $app --description="Low-code programming for event-driven applications" --log="/var/log/$app/$app.log"
2019-05-29 00:20:58 +02:00
#=================================================
# 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"
2019-05-29 00:20:58 +02:00
#=================================================
# RELOAD NGINX
#=================================================
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
#=================================================
ynh_script_progression --message="Upgrade of Node-RED completed" --last