2019-05-29 00:20:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2022-01-27 00:17:52 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
|
2024-02-24 01:45:02 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
2022-01-27 00:17:52 +01:00
|
|
|
|
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
|
|
|
|
2021-09-18 17:55:46 +02:00
|
|
|
# Flows were stored in file named after the hostname.
|
|
|
|
# Not very portable. Let's fix that.
|
2024-01-24 12:38:53 +01:00
|
|
|
if [[ ! -f "$install_dir/data/flows.json" ]]; then
|
|
|
|
if [[ -f "$install_dir/data/flows_$(hostname).json" ]]; then
|
|
|
|
mv "$install_dir/data/flows_$(hostname)_cred.json" "$install_dir/data/flows_cred.json"
|
|
|
|
mv "$install_dir/data/flows_$(hostname).json" "$install_dir/data/flows.json"
|
|
|
|
elif [[ -f "$install_dir/data/>>" ]]; then
|
|
|
|
mv "$install_dir/data/>>_cred" "$install_dir/data/flows_cred.json"
|
|
|
|
mv "$install_dir/data/>>" "$install_dir/data/flows.json"
|
|
|
|
fi
|
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
|
2024-01-24 12:38:53 +01:00
|
|
|
ynh_remove_logrotate
|
|
|
|
ynh_secure_remove --file="/var/log/$app"
|
2021-12-26 17:53:09 +01:00
|
|
|
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.
|
2024-01-24 12:38:53 +01:00
|
|
|
if yunohost firewall list | grep -q "\- $port$"; then
|
2024-02-24 01:45:02 +01:00
|
|
|
ynh_exec_warn_less yunohost firewall disallow TCP "$port"
|
2020-11-07 19:49:00 +01:00
|
|
|
fi
|
|
|
|
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
2024-01-24 12:38:53 +01:00
|
|
|
# UPGRADE NODEJS
|
2019-10-13 18:52:07 +02:00
|
|
|
#=================================================
|
2024-01-24 12:38:53 +01:00
|
|
|
ynh_script_progression --message="Upgrading NodeJS..."
|
2019-10-13 18:52:07 +02:00
|
|
|
|
2024-01-24 12:38:53 +01: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
|
|
|
|
#=================================================
|
2024-01-24 12:38:53 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=2
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2024-01-24 12:38:53 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="data"
|
2019-10-13 19:50:59 +02:00
|
|
|
|
2024-01-24 12:38:53 +01:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R "$app:www-data" "$install_dir"
|
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
|
|
|
|
|
2024-01-24 12:38:53 +01:00
|
|
|
pushd "$install_dir"
|
|
|
|
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
|
2024-01-24 12:38:53 +01:00
|
|
|
ynh_add_config --template="settings.js" --destination="$install_dir/data/settings.js"
|
2024-01-24 12:25:21 +01:00
|
|
|
if [[ ! -f "$install_dir/data/settings.user.js" ]] ; then
|
2024-01-24 12:38:53 +01:00
|
|
|
ynh_add_config --template="settings.user.js" --destination="$install_dir/data/settings.user.js"
|
2021-12-26 14:19:45 +01:00
|
|
|
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
|
2024-01-24 12:38:53 +01:00
|
|
|
ynh_add_config --template="flows.json" --destination="$install_dir/data/flows.json"
|
2021-09-23 21:13:59 +02:00
|
|
|
fi
|
|
|
|
|
2024-01-24 12:38:53 +01:00
|
|
|
chmod 400 "$install_dir/data/settings.js"
|
2024-01-24 12:25:21 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
2024-01-24 12:38:53 +01:00
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2020-12-07 09:50:58 +01:00
|
|
|
#=================================================
|
2024-01-24 12:38:53 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2020-12-07 09:50:58 +01:00
|
|
|
#=================================================
|
2024-01-24 12:38:53 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
2020-12-07 09:50:58 +01:00
|
|
|
|
2024-01-24 12:38:53 +01:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
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
|
|
|
|
2024-02-24 01:45:02 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-01-27 00:17:52 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|