mirror of
https://github.com/YunoHost-Apps/nodered_ynh.git
synced 2024-09-03 19:46:25 +02:00
116 lines
4.3 KiB
Bash
Executable file
116 lines
4.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
|
|
|
#=================================================
|
|
# 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" && -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"
|
|
# Flows could be stored in a file named '>>'.
|
|
# Definitely weird, let's fix that.
|
|
elif [[ ! -f "$install_dir/data/flows.json" && -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
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
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"
|
|
fi
|
|
|
|
chown -R $app: "$install_dir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
yunohost service add $app --description="Low-code programming for event-driven applications" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# Install through npm
|
|
#=================================================
|
|
ynh_script_progression --message="Installing Node-RED..." --weight=5
|
|
|
|
pushd $install_dir
|
|
ynh_use_nodejs
|
|
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="../conf/settings.js" --destination="$install_dir/data/settings.js"
|
|
chmod 400 "$install_dir/data/settings.js"
|
|
chown $app:$app "$install_dir/data/settings.js"
|
|
|
|
if [[ ! -f "$install_dir/data/settings.user.js" ]] ; then
|
|
ynh_add_config --template="../conf/settings.user.js" --destination="$install_dir/data/settings.user.js"
|
|
chmod 400 "$install_dir/data/settings.user.js"
|
|
chown $app:$app "$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="../conf/flows.json" --destination="$install_dir/data/flows.json"
|
|
fi
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|