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)
|
2019-10-13 12:30:35 +02:00
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
|
2021-05-24 15:26:59 +02:00
|
|
|
if [[ $path_url = "/" ]]
|
2021-05-23 15:45:29 +02:00
|
|
|
then
|
2021-05-24 15:26:59 +02:00
|
|
|
nodes_url="/"
|
|
|
|
admin_url="/admin"
|
2021-05-23 15:45:29 +02:00
|
|
|
else
|
2021-05-24 15:26:59 +02:00
|
|
|
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
|
|
|
|
|
2021-05-24 15:26:59 +02:00
|
|
|
if ! ynh_permission_exists --permission="admin"; then
|
2021-05-23 15:45:29 +02:00
|
|
|
# Create the required permissions
|
2021-05-24 15:26:59 +02:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2021-05-24 15:26:59 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2019-10-13 18:52:07 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL NODEJS
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-25 11:37:52 +02:00
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
2019-10-13 18:52:07 +02:00
|
|
|
|
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
|
|
|
|
|
2019-10-13 12:30:35 +02:00
|
|
|
#=================================================
|
|
|
|
# Install through npm
|
|
|
|
#=================================================
|
2020-10-16 10:50:34 +02:00
|
|
|
ynh_script_progression --message="Installing Node-RED..." --weight=30
|
2019-10-13 12:30:35 +02:00
|
|
|
|
2021-05-24 15:26:59 +02:00
|
|
|
chown -R root:root $final_path
|
|
|
|
chown -R $app: $final_path/data
|
2019-10-13 19:50:59 +02:00
|
|
|
|
2021-05-25 10:41:05 +02:00
|
|
|
ynh_use_nodejs
|
|
|
|
|
2019-10-13 12:30:35 +02:00
|
|
|
pushd $final_path
|
2021-05-25 10:41:05 +02:00
|
|
|
ynh_exec_warn_less exec_as $app $ynh_node_load_PATH $ynh_npm install --production
|
|
|
|
ynh_exec_warn_less exec_as $app $ynh_node_load_PATH $ynh_npm install node-red-dashboard
|
2019-10-13 12:30:35 +02:00
|
|
|
popd
|
|
|
|
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-10-16 10:50:34 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2020-10-16 10:50:34 +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
|
|
|
|
2021-05-24 15:26:59 +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
|
2019-10-13 12:30:35 +02:00
|
|
|
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
|
|
|
|
2021-05-24 15:26:59 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-10-16 10:50:34 +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-10-16 10:50:34 +02:00
|
|
|
ynh_script_progression --message="Upgrade of Node-RED completed" --last
|