1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/petrolette_ynh.git synced 2024-09-03 19:56:26 +02:00
petrolette_ynh/scripts/upgrade

150 lines
5 KiB
Text
Raw Normal View History

2021-04-06 13:20:29 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
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)
port=$(ynh_app_setting_get --app=$app --key=port)
https_port=$(ynh_app_setting_get --app=$app --key=https_port)
2021-04-06 13:20:29 +02:00
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
2021-04-06 13:20:29 +02:00
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2022-02-06 18:08:55 +01:00
ynh_clean_check_starting
# Restore it if the upgrade fails
2021-04-06 13:20:29 +02:00
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2022-02-06 18:08:55 +01:00
ynh_systemd_action --service_name=$app --action=stop --log_path=systemd --line_match="Stopped"
2021-04-06 13:20:29 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=8
# Create a dedicated user (if not existing)
2022-02-06 18:08:55 +01:00
ynh_system_user_create --username=$app --home_dir="$final_path"
2021-04-06 13:20:29 +02:00
#=================================================
# 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="$final_path"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3
# Create a dedicated NGINX config
2021-04-06 13:20:29 +02:00
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
2021-04-06 13:20:29 +02:00
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=2
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
#=================================================
# SPECIFIC UPGRADE
2021-04-06 13:20:29 +02:00
#=================================================
# UPDATE APP
#=================================================
ynh_script_progression --message="Upgrading the app..." --weight=5
pushd $final_path
# set port in configuration file
sed -i "/HTTP_PORT/s/[0-9]*[0-9]/$port/" package.json
sed -i "/HTTPS_PORT/s/[0-9]*[0-9]/$https_port/" package.json
[[ -v HOME ]] && TMP_HOME=$HOME
HOME=$(pwd)
ynh_use_nodejs
ynh_npm install
[[ -v TMP_HOME ]] && HOME=$TMP_HOME || unset HOME
2021-04-06 13:20:29 +02:00
popd
2022-02-06 18:08:55 +01:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
2021-04-06 13:20:29 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
2021-04-06 13:20:29 +02:00
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2022-02-06 18:08:55 +01:00
yunohost service add $app --description="The news reader that doesn't know you"
2021-04-06 13:20:29 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
2022-02-06 18:08:55 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Directory created"
2021-04-06 13:20:29 +02:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last