2022-07-11 20:34:24 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2024-01-18 21:02:26 +01:00
|
|
|
# STANDARD UPGRADE STEPS
|
2022-07-11 20:34:24 +02:00
|
|
|
#=================================================
|
2024-01-18 21:02:26 +01:00
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2022-08-15 16:56:45 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
if [ -z "${debug_enabled:-}" ]; then
|
|
|
|
debug_enabled="0"
|
|
|
|
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
|
2022-08-15 16:56:45 +02:00
|
|
|
fi
|
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
if [ -z "${log_level:-}" ]; then
|
|
|
|
log_level="WARNING"
|
|
|
|
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
|
2022-08-15 16:56:45 +02:00
|
|
|
fi
|
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
if [ -z "${admin_email:-}" ]; then
|
|
|
|
admin_email="${admin}@${domain}"
|
|
|
|
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
|
2022-08-15 16:56:45 +02:00
|
|
|
fi
|
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
if [ -z "${default_from_email:-}" ]; then
|
|
|
|
default_from_email="${app}@${domain}"
|
|
|
|
ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from_email"
|
2022-08-15 16:56:45 +02:00
|
|
|
fi
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-10-04 10:20:28 +02:00
|
|
|
ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-18 21:02:26 +01:00
|
|
|
# PIP INSTALLATION
|
2022-07-11 20:34:24 +02:00
|
|
|
#=================================================
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_script_progression --message="Installing project via pip..." --weight=45
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
# Always recreate everything fresh with current python version
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_secure_remove "$install_dir/venv"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
_install_fmd_venv
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
chmod o-rwx "$install_dir"
|
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# copy config files
|
|
|
|
# ================================================
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_script_progression --message="Create $app configuration files..."
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_add_config --template="manage.py" --destination="$install_dir/manage.py"
|
|
|
|
chmod +x "$install_dir/manage.py"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_add_config --template="settings.py" --destination="$install_dir/settings.py"
|
|
|
|
ynh_add_config --template="setup_user.py" --destination="$install_dir/setup_user.py"
|
|
|
|
ynh_add_config --template="urls.py" --destination="$install_dir/urls.py"
|
|
|
|
ynh_add_config --template="wsgi.py" --destination="$install_dir/wsgi.py"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MIGRATE PYINVENTORY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10
|
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
pushd "$install_dir"
|
|
|
|
# Just for debugging:
|
|
|
|
ynh_exec_as "$app" "$venvpython" ./manage.py diffsettings
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_exec_as "$app" "$venvpython" ./manage.py migrate --no-input
|
|
|
|
ynh_exec_as "$app" "$venvpython" ./manage.py collectstatic --no-input
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
|
|
|
ynh_exec_as "$app" "$venvpython" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
# Check the configuration
|
|
|
|
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
|
|
|
|
ynh_exec_as "$app" "$venvpython" ./manage.py check --deploy || true
|
|
|
|
popd
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-18 21:02:26 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2022-07-11 20:34:24 +02:00
|
|
|
#=================================================
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_add_nginx_config
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_add_systemd_config --service="$app" --template="systemd.service"
|
|
|
|
yunohost service add "$app" --description="Digital signage system for high schools" --log="/var/log/$app/$app.log"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
2024-01-18 21:02:26 +01:00
|
|
|
ynh_use_logrotate --non-append
|
2024-01-19 14:54:54 +01:00
|
|
|
chmod o-rwx "/var/log/$app"
|
|
|
|
chown -R "$app:" "/var/log/$app"
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-08-15 16:56:45 +02:00
|
|
|
# Start the app server via systemd
|
2022-07-11 20:34:24 +02:00
|
|
|
#=================================================
|
2022-10-04 10:20:28 +02:00
|
|
|
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
|
2022-07-11 20:34:24 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|