#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # ACTIVATE MAINTENANCE MODE #================================================= ynh_maintenance_mode_ON #================================================= # INSTALL LXD #================================================= ynh_script_progression --message="Installing LXD... (this make take a long time!)" if ! yunohost app list --output-as json --quiet | jq -e '.apps[] | select(.id == "lxd")' >/dev/null; then yunohost app install --force https://github.com/YunoHost-Apps/lxd_ynh fi #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping $app's systemd service..." ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --line_match="Stopped YunoRunner CI" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." if [ ! -d "$install_dir/.git/" ]; then ynh_exec_as "$app" git -C "$install_dir" init -b main git -C "$install_dir" remote add origin "$yunorunner_repository" fi # Close a legacy port if yunohost firewall list | grep -q "\- $port$"; then ynh_exec_warn_less yunohost firewall disallow TCP "$port" fi if [[ -z "${context:-}" ]]; then if grep -q "CI_APP" /etc/hosts; then context=official_infra else context=personal_ci fi ynh_app_setting_set --app="$app" --key="context" --value="$context" fi if [[ -z "${cluster:-}" ]]; then if lxc cluster list >/dev/null 2>&1; then cluster=1 else cluster=0 fi ynh_app_setting_set --app="$app" --key="cluster" --value="$cluster" fi if [[ -z "${backend:-}" ]]; then backend=lxd ynh_app_setting_set --app="$app" --key="backend" --value="$backend" fi # Values now use underscore if echo "$context" | grep -- -; then context=$(echo "$context" | tr - _) ynh_app_setting_set --app="$app" --key="context" --value="$context" fi # cluster is now a boolean if [[ "$cluster" == "cluster" ]] || [[ "$cluster" == "no" ]]; then if [[ "$cluster" == "cluster" ]]; then cluster=1 else cluster=0 fi ynh_app_setting_set --app="$app" --key="cluster" --value="$cluster" fi # Remove Pythonz ynh_secure_remove --file="$install_dir/.pythonz" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src pushd "$install_dir" ynh_exec_as "$app" git fetch --quiet --depth=1 origin "$yunorunner_release" ynh_exec_as "$app" git reset --quiet --hard FETCH_HEAD popd chmod -R o-rwx "$install_dir" chown -R "$app:$app" "$install_dir" #================================================= # INSTALL PYTHON DEPENDENCIES #================================================= ynh_script_progression --message="Installing Python dependencies..." pushd "$install_dir" python3 -m venv venv venv/bin/pip install --upgrade pip venv/bin/pip install -r requirements-frozen.txt popd #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a config file..." ynh_backup_if_checksum_is_different --file="$install_dir/config.py" chmod 400 "$install_dir/config.py" chown "$app:$app" "$install_dir/config.py" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config yunohost service add "$app" --description="$app daemon for YunoRunner" $(exposed_ports_if_cluster) ynh_add_config --template="cron" --destination="/etc/cron.d/$app" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting $app's systemd service..." ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30 #================================================= # DEACTIVE MAINTENANCE MODE #================================================= ynh_maintenance_mode_OFF #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed"