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

162 lines
5 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
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="Loading installation settings..."
2018-08-26 19:04:08 +02:00
app=$YNH_APP_INSTANCE_NAME
2021-01-06 11:55:46 +01:00
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)
2018-08-26 19:04:08 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="Ensuring downward compatibility..."
2018-08-26 19:04:08 +02:00
# If port doesn't exist, create it
if [ -z "$port" ]; then
port=4242
2021-01-06 11:55:46 +01:00
ynh_app_setting_set --app=$app --key=port --value=$port
2019-02-14 20:21:06 +01:00
fi
2018-08-26 19:04:08 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="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
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="Upgrading source files..."
2018-08-26 19:04:08 +02:00
2021-01-05 17:37:11 +01:00
pushd "$final_path"
2021-01-06 11:55:46 +01:00
git fetch
git reset --hard origin/master
2021-01-05 17:37:11 +01:00
popd
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:46:11 +01:00
# NGINX CONFIGURATION
2018-08-26 19:04:08 +02:00
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="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
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="Upgrading dependencies..."
2018-08-26 19:04:08 +02:00
2021-01-06 11:55:46 +01:00
ynh_install_app_dependencies $pkg_dependencies
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
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2019-02-14 19:46:11 +01:00
# Create a dedicated user (if not existing)
2021-01-06 11:55:46 +01:00
ynh_system_user_create --username=$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
#=================================================
2021-01-06 11:55:46 +01:00
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="/etc/systemd/system/$app.service"
2018-11-04 20:48:37 +01:00
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
#=================================================
2021-01-06 11:55:46 +01:00
# ENABLE SERVICE IN ADMIN PANEL
2018-08-26 19:04:08 +02:00
#=================================================
2021-01-06 11:55:46 +01:00
yunohost service add $app --description="$app daemon for YunoRunner"
2018-08-26 19:04:08 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="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
#=================================================
2021-01-06 11:55:46 +01:00
ynh_script_progression --message="Upgrade of $app completed"