1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/yunorunner_ynh.git synced 2024-09-03 20:36:13 +02:00
yunorunner_ynh/scripts/upgrade
2021-01-06 11:55:46 +01:00

161 lines
5 KiB
Bash

#!/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)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# If port doesn't exist, create it
if [ -z "$port" ]; then
port=4242
ynh_app_setting_set --app=$app --key=port --value=$port
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading... (may take a while)"
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..."
pushd "$final_path"
git fetch
git reset --hard origin/master
popd
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX configuration..."
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_add_systemd_config
echo -e "\e[93m\e[1m[WARN]\e[0m Please have a look to the diff of your systemd conf file. The upgrade could have broken this CI." >&2
#=================================================
# CHANGE PORT IN YUNORUNNER
#=================================================
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="/etc/systemd/system/$app.service"
ynh_store_file_checksum "/etc/systemd/system/$app.service"
systemctl daemon-reload
#=================================================
# Fix current websocket version error (2019-02-14)
#=================================================
pushd $final_path
ve3/bin/pip3 uninstall -y websockets
ve3/bin/pip3 install 'websockets>=6.0,<7.0'
ve3/bin/pip3 install -r requirements-frozen.txt
popd
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R $app:root $final_path
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --description="$app daemon for YunoRunner"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX..."
ynh_system_reload --service_name=nginx
#=================================================
# RESTART YUNORUNNER
#=================================================
ynh_system_reload --service_name=$app --action=restart
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_OFF
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"