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-05 17:37:11 +01:00

183 lines
5.2 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_print_info "Ensuring downward compatibility..."
# If port doesn't exist, create it
if [ -z "$port" ]; then
port=4242
ynh_app_setting_set $app port $port
fi
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
ynh_print_info "Closing port $port"
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_print_info "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
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info "Upgrading source files..."
pushd "$final_path"
git fetch
git reset --hard origin/master
popd
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_print_info "Upgrading nginx configuration..."
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_print_info "Upgrading dependencies..."
ynh_install_app_dependencies python-virtualenv sqlite3 zlib1g-dev
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_print_info "Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create $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 "__PORT__" "$port" "/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
#=================================================
# SETUP SSOWAT
#=================================================
ynh_print_info "Upgrading SSOwat configuration..."
# Make app public
ynh_app_setting_set $app skipped_uris "/"
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "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_print_info "Upgrade of $app completed"