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
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-10-14 17:45:28 +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
|
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
if [[ ! -d "$final_path/.git/" ]]
|
|
|
|
then
|
|
|
|
git init "$final_path"
|
|
|
|
pushd "$final_path"
|
|
|
|
git remote add origin "$yunorunner_repository"
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove Pythonz
|
|
|
|
ynh_secure_remove --file="$final_path/.pythonz"
|
|
|
|
|
2019-02-14 20:21:06 +01:00
|
|
|
#=================================================
|
|
|
|
# CLOSE A PORT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if yunohost firewall list | grep -q "\- $port$"
|
|
|
|
then
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Closing port $port"
|
2019-02-14 20:21:06 +01:00
|
|
|
ynh_exec_warn_less yunohost firewall disallow TCP $port
|
|
|
|
fi
|
|
|
|
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +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 () {
|
2021-03-17 21:13:57 +01:00
|
|
|
# Restore it if the upgrade fails
|
2018-08-26 19:04:08 +02:00
|
|
|
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
|
2021-03-17 21:13:57 +01:00
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped YunoRunner CI"
|
|
|
|
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
pushd "$final_path"
|
|
|
|
git fetch --quiet --depth=1 origin "$yunorunner_release"
|
|
|
|
git reset --quiet --hard FETCH_HEAD
|
|
|
|
popd
|
|
|
|
fi
|
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-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
# Create a dedicated NGINX config
|
2019-02-14 19:46:11 +01:00
|
|
|
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
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# INSTALL PYTHON DEPENDENCIES
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Installing Python dependencies..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
pushd $final_path
|
|
|
|
python3 -m venv venv
|
|
|
|
venv/bin/pip install --upgrade pip
|
|
|
|
venv/bin/pip install -r requirements-frozen.txt
|
|
|
|
#Fix current websocket version error (2019-02-14)
|
|
|
|
venv/bin/pip uninstall -y websockets
|
|
|
|
venv/bin/pip install 'websockets>=6.0,<7.0'
|
|
|
|
popd
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2018-10-14 17:45:28 +02:00
|
|
|
#=================================================
|
2018-08-26 19:04:08 +02:00
|
|
|
# SETUP SYSTEMD
|
2018-10-14 17:45:28 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2018-10-14 17:45:28 +02:00
|
|
|
|
2018-08-26 19:04:08 +02:00
|
|
|
ynh_add_systemd_config
|
2018-10-14 17:45:28 +02:00
|
|
|
|
2019-02-14 20:12:22 +01:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# CONFIGURE YUNORUNNER
|
2019-02-14 20:12:22 +01:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Configuring YunoRunner..."
|
2019-02-14 20:12:22 +01:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_add_config --template="yunorunner.config.py" --destination="$final_path/config.py"
|
2019-02-14 20:12:22 +01:00
|
|
|
|
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
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Securing 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-03-17 21:13:57 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
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
|
|
|
|
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# START SYSTEMD SERVICE
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started YunoRunner CI"
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2018-08-26 19:36:20 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# DEACTIVE MAINTENANCE MODE
|
2018-08-26 19:36:20 +02:00
|
|
|
#=================================================
|
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_maintenance_mode_OFF
|
2018-08-26 19:36:20 +02:00
|
|
|
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
# RELOAD NGINX
|
2018-08-26 19:04:08 +02:00
|
|
|
#=================================================
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2018-08-26 19:04:08 +02:00
|
|
|
|
2021-03-17 21:13:57 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
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"
|