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

185 lines
5.3 KiB
Text
Raw Normal View History

2018-08-26 19:04:08 +02:00
#!/bin/bash
#=================================================
2019-02-14 19:46:11 +01:00
# GENERIC START
2018-08-26 19:04:08 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Loading installation settings..."
2018-08-26 19:04:08 +02:00
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)
2018-08-26 19:04:08 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Ensuring downward compatibility..."
2018-08-26 19:04:08 +02:00
# If port doesn't exist, create it
if [ -z "$port" ]; then
port=4242
ynh_app_setting_set $app port $port
fi
2019-02-14 20:21:06 +01:00
#=================================================
# 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
2018-08-26 19:04:08 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Backing up the app before upgrading... (may take a while)"
2018-08-26 19:04:08 +02:00
# 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
#=================================================
2019-02-14 19:46:11 +01:00
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
2018-08-26 19:04:08 +02:00
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Upgrading source files..."
2018-08-26 19:04:08 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2019-02-14 19:46:11 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
2018-08-26 19:04:08 +02:00
fi
#=================================================
2019-02-14 19:46:11 +01:00
# NGINX CONFIGURATION
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Upgrading nginx configuration..."
2018-08-26 19:04:08 +02:00
2019-02-14 19:46:11 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
# UPGRADE DEPENDENCIES
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Upgrading dependencies..."
ynh_install_app_dependencies python-virtualenv sqlite3 zlib1g-dev
2018-08-26 19:04:08 +02:00
#=================================================
2018-08-26 19:36:20 +02:00
# CREATE DEDICATED USER
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create $app
2018-08-26 19:04:08 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_add_systemd_config
2019-01-10 14:17:53 +01:00
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
2018-08-26 19:04:08 +02:00
#=================================================
# CHANGE PORT IN YUNORUNNER
#=================================================
2018-11-04 20:48:37 +01:00
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
2019-02-14 20:57:25 +01:00
ve3/bin/pip3 uninstall -y websockets
2019-03-28 21:26:16 +01:00
ve3/bin/pip3 install 'websockets>=6.0,<7.0'
ve3/bin/pip3 install -r requirements-frozen.txt
popd
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
# GENERIC FINALIZATION
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
# SECURE FILES AND DIRECTORIES
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
# Set permissions on app files
2018-08-28 12:47:16 +02:00
chown -R $app:root $final_path
2018-08-26 19:04:08 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Upgrading SSOwat configuration..."
2018-08-26 19:04:08 +02:00
2018-08-26 19:36:20 +02:00
# Make app public
ynh_app_setting_set $app skipped_uris "/"
2018-08-26 19:04:08 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2019-02-14 19:46:11 +01:00
ynh_print_info "Reloading nginx..."
2018-08-26 19:04:08 +02:00
ynh_system_reload --service_name=nginx
2018-08-26 19:36:20 +02:00
#=================================================
# RESTART YUNORUNNER
#=================================================
ynh_system_reload --service_name=$app --action=restart
2018-08-26 19:36:20 +02:00
2018-08-26 19:04:08 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_OFF
2019-02-14 19:46:11 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Upgrade of $app completed"