1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/zeroui_ynh.git synced 2024-09-03 18:05:57 +02:00
zeroui_ynh/scripts/upgrade
2023-08-27 00:16:10 +02:00

110 lines
3.7 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# CHECK IF THE APP CAN BE INSTALLED
#=================================================
# Testing if ZeroTier is installed
yunohost app list | grep -q "id: zerotier" || ynh_die "ZeroTier is needed, but it is not installed. There is a package for that!"
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
#ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#=================================================
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
ynh_use_nodejs
$nodejs_path/corepack enable
$nodejs_path/corepack prepare yarn@stable --activate
# Prevent ERR_OSSL_EVP_UNSUPPORTED error
export NODE_OPTIONS=--openssl-legacy-provider
ynh_script_progression --message="Building the backend..." --weight=3
pushd $install_dir/backend
$nodejs_path/yarn install
popd
ynh_script_progression --message="Building the frontend..." --weight=3
pushd $install_dir/frontend
$nodejs_path/yarn install
$nodejs_path/yarn build
popd
fi
chown -R $app:$app "$install_dir"
chown $app:www-data "$install_dir"
chown $app:www-data "$install_dir/frontend"
chown -R $app:www-data "$install_dir/frontend/public"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_add_nginx_config
ynh_add_systemd_config
yunohost service add $app --description="ZeroTier Controller Web UI"
#=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
# Let's retrieve information on the ZeroTier installation
zt_token="$(</var/lib/zerotier-one/authtoken.secret)"
zt_addr="localhost:$(</var/lib/zerotier-one/zerotier-one.port)"
ynh_add_config --template="env" --destination="$install_dir/.env"
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last