#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # INITIALIZE AND STORE SETTINGS #================================================= admin_email=$(ynh_user_get_info --username="$admin" --key="mail") #================================================= # STOP SYSTEMD SERVICES #================================================= ynh_script_progression --message="Stopping $app's systemd services..." --weight=1 ynh_systemd_action --service_name="$app.socket" --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-beat" --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="/var/log/$app/$app.log" systemctl disable "$app.socket" --quiet systemctl disable "$app" --quiet systemctl disable "$app-beat" --quiet systemctl disable "$app-celery" --quiet #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 if [ -n "${data_path:-}" ]; then ynh_app_setting_delete --app="$app" --key=data_path ynh_app_setting_delete --app="$app" --key=db_pwd ynh_app_setting_delete --app="$app" --key=admin_email fi if [[ -n "${random_key:-}" ]]; then secret_key="$random_key" ynh_app_setting_delete --app="$app" --key=random_key ynh_app_setting_set --app="$app" --key=secret_key --value="$random_key" fi if [ -f "$install_dir/requirements.txt" ]; then mkdir "$install_dir/sources" # Move to $install_dir/sources find "$install_dir" -maxdepth 1 -mindepth 1 -not -name sources -exec mv -t "$install_dir/sources" {} + mv "$install_dir/sources/envs" "$install_dir" fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/sources" --full_replace=1 #================================================= # APP INITIAL CONFIGURATION #================================================= ynh_script_progression --message="Adding $app's configuration files..." --weight=1 mkdir -p "$env_path" echo "$admin <$admin_email>" > "$env_path/ADMINS" echo "None" > "$env_path/BROKER_POOL_LIMIT" echo "redis://localhost:6379" > "$env_path/BROKER_URL" echo "postgres://$db_user:$db_pwd@localhost:5432/$db_name" > "$env_path/DATABASE_URL" echo "False" > "$env_path/DEBUG" echo "$domain" > "$env_path/DEFAULT_BASE_URL" echo "$app@$domain" > "$env_path/DEFAULT_FROM_EMAIL" echo "django.core.mail.backends.console.EmailBackend" > "$env_path/EMAIL_BACKEND" echo "$data_dir" > "$env_path/MEDIA_ROOT" echo "$secret_key" > "$env_path/SECRET_KEY" echo "$app@$domain" > "$env_path/SERVER_EMAIL" set_permissions #================================================= # UPDATE VIRTUALENV #================================================= ynh_script_progression --message="Upgrading Python virtualenv..." --weight=2 set_up_virtualenv ynh_script_progression --message="Collecting static..." collect_static #================================================= # PERFORM DATABASE MIGRATIONS #================================================= ynh_script_progression --message="Performing database migrations..." --weight=2 upgrade_db set_permissions #================================================= # 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="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" ynh_add_systemd_config --service="$app-celery" --template systemd-celery.service ynh_add_systemd_config --service="$app-beat" --template systemd-beat.service # Some workaround bc ynh_add_system_config doesn't know sockets ynh_add_systemd_config --service="$app-socket" --template systemd.socket systemctl disable "$app-socket.service" --quiet mv "/etc/systemd/system/$app-socket.service" "/etc/systemd/system/$app.socket" systemctl daemon-reload --quiet #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app.socket" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last