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)
|
|
|
|
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
2021-05-23 15:45:29 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5
|
2021-05-23 15:45:29 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2022-01-27 00:17:52 +01:00
|
|
|
# Restore it if the upgrade fails
|
2021-05-23 15:45:29 +02:00
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2022-01-27 00:17:52 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop"
|
|
|
|
|
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-09-18 17:20:18 +02:00
|
|
|
# After 1.3.5~ynh2, permissions have been reworked
|
|
|
|
if ynh_permission_exists --permission="admin"; then
|
2021-09-24 23:57:36 +02:00
|
|
|
# Delete the admin permission
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_permission_delete --permission="admin"
|
2021-09-24 23:57:36 +02:00
|
|
|
# We use main as admin permission
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_permission_url --permission="main" --url="/admin"
|
2021-10-03 14:10:03 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! ynh_permission_exists --permission="ui"; then
|
2021-09-18 17:20:18 +02:00
|
|
|
# Create ui permission, for the dashboard
|
|
|
|
ynh_permission_create --permission="ui" --url="/ui" --show_tile=true
|
2021-10-03 14:10:03 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! ynh_permission_exists --permission="endpoints"; then
|
2021-09-18 17:20:18 +02:00
|
|
|
# Create endpoints permission
|
2021-09-23 21:13:59 +02:00
|
|
|
ynh_permission_create --permission="endpoints" --url="/" --show_tile=false
|
2021-10-03 14:10:03 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Transfer the publicness of the app to ui and endpoints
|
|
|
|
if ynh_permission_has_user --permission=main --user=visitors; then
|
|
|
|
ynh_permission_update --permission="ui" --add="visitors"
|
|
|
|
ynh_permission_update --permission="endpoints" --add="visitors"
|
2021-09-24 23:57:36 +02:00
|
|
|
# Remove visitor access to the admin panel
|
|
|
|
ynh_permission_update --permission="main" --remove="visitors"
|
2021-09-02 21:42:18 +02:00
|
|
|
fi
|
|
|
|
|
2021-09-18 17:55:46 +02:00
|
|
|
# Flows were stored in file named after the hostname.
|
|
|
|
# Not very portable. Let's fix that.
|
2021-12-16 11:49:03 +01:00
|
|
|
if [[ ! -f "$final_path/data/flows.json" && -f "$final_path/data/flows_$(hostname).json" ]]; then
|
2021-09-18 17:55:46 +02:00
|
|
|
mv "$final_path/data/flows_$(hostname)_cred.json" "$final_path/data/flows_cred.json"
|
|
|
|
mv "$final_path/data/flows_$(hostname).json" "$final_path/data/flows.json"
|
2021-12-16 11:49:03 +01:00
|
|
|
# Flows could be stored in a file named '>>'.
|
|
|
|
# Definitely weird, let's fix that.
|
|
|
|
elif [[ ! -f "$final_path/data/flows.json" && -f "$final_path/data/>>" ]]; then
|
|
|
|
mv "$final_path/data/>>_cred" "$final_path/data/flows_cred.json"
|
|
|
|
mv "$final_path/data/>>" "$final_path/data/flows.json"
|
2021-09-18 17:55:46 +02:00
|
|
|
fi
|
|
|
|
|
2021-12-26 17:53:09 +01:00
|
|
|
# Remove logrotate and log directory, we use syslog now
|
|
|
|
if [[ -d "/etc/logrotate.d/$app" ]]; then
|
|
|
|
ynh_remove_logrotate
|
|
|
|
ynh_secure_remove --file="/var/log/$app"
|
|
|
|
fi
|
|
|
|
|
2020-11-07 19:49:00 +01:00
|
|
|
# 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
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_script_progression --message="Closing port $port..." --weight=1
|
2020-11-07 19:49:00 +01:00
|
|
|
ynh_exec_warn_less yunohost firewall disallow TCP $port
|
|
|
|
fi
|
|
|
|
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
# CREATE DEDICATED USER
|
2019-10-13 18:52:07 +02:00
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2019-10-13 18:52:07 +02:00
|
|
|
|
2022-01-27 00:17:52 +01:00
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
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
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=2
|
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
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
# NGINX CONFIGURATION
|
2019-10-13 19:50:59 +02:00
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2019-10-13 19:50:59 +02:00
|
|
|
|
2022-01-27 00:17:52 +01:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
|
|
|
|
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-10-13 19:50:59 +02:00
|
|
|
|
2022-01-27 00:17:52 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2019-10-13 12:30:35 +02:00
|
|
|
#=================================================
|
|
|
|
# Install through npm
|
|
|
|
#=================================================
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_script_progression --message="Installing Node-RED..." --weight=5
|
2019-10-13 12:30:35 +02:00
|
|
|
|
2021-05-25 10:41:05 +02:00
|
|
|
ynh_use_nodejs
|
|
|
|
|
2021-06-09 20:42:21 +02:00
|
|
|
chown -R $app: "$final_path"
|
|
|
|
|
2019-10-13 12:30:35 +02:00
|
|
|
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
|
2019-10-13 12:30:35 +02:00
|
|
|
popd
|
|
|
|
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
# UPDATE A CONFIG FILE
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
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"
|
2021-12-26 14:19:45 +01:00
|
|
|
if [[ ! -f "$final_path/data/settings.user.js" ]] ; then
|
|
|
|
ynh_add_config --template="../conf/settings.user.js" --destination="$final_path/data/settings.user.js"
|
|
|
|
fi
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2021-09-23 21:13:59 +02:00
|
|
|
# Small hack to have the "/" path answer with a 200 code to satisfy the CI
|
|
|
|
if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then
|
|
|
|
ynh_add_config --template="../conf/flows.json" --destination="$final_path/data/flows.json"
|
|
|
|
fi
|
|
|
|
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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"
|
2021-12-26 14:19:45 +01:00
|
|
|
# make settings.js readonly
|
|
|
|
chmod a-w "$final_path/data/settings.js"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2020-12-07 09:50:58 +01:00
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2020-12-07 09:50:58 +01:00
|
|
|
#=================================================
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2020-12-07 09:50:58 +01:00
|
|
|
|
2022-01-27 21:38:13 +01:00
|
|
|
yunohost service add $app --description="Low-code programming for event-driven applications"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
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
|
|
|
|
#=================================================
|
|
|
|
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|