#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Flows were stored in file named after the hostname. # Not very portable. Let's fix that. 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 fi # 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 # 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_exec_warn_less yunohost firewall disallow TCP $port fi #================================================= # UPGRADE NODEJS #================================================= ynh_script_progression --message="Upgrading NodeJS..." ynh_install_nodejs --nodejs_version="$nodejs_version" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Upgrading source files..." --weight=2 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="data" chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # SPECIFIC UPGRADE #================================================= # Install through npm #================================================= ynh_script_progression --message="Installing Node-RED..." --weight=5 ynh_use_nodejs 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 popd #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." # Set up the settings file ynh_add_config --template="settings.js" --destination="$install_dir/data/settings.js" if [[ ! -f "$install_dir/data/settings.user.js" ]] ; then ynh_add_config --template="settings.user.js" --destination="$install_dir/data/settings.user.js" fi # 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="flows.json" --destination="$install_dir/data/flows.json" fi chmod 400 "$install_dir/data/settings.js" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # 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" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_systemd_action --service_name=$app --action="start" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last