1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/scovie_ynh.git synced 2024-09-03 20:16:29 +02:00
scovie_ynh/scripts/upgrade

228 lines
8.3 KiB
Text
Raw Normal View History

2023-05-26 19:09:08 +02:00
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
#REMOVEME? admin=$(ynh_app_setting_get --app="$app" --key=admin)
#REMOVEME? public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir)
#REMOVEME? log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app="$app" --key=path)
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
#REMOVEME? port=$(ynh_app_setting_get --app="$app" --key=port)
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
#REMOVEME? db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name="$app")
#REMOVEME? db_user=$db_name
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
#REMOVEME? redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
2023-05-26 19:09:08 +02:00
#-------------------------------------------------
# config_panel.toml settings:
2024-01-18 13:19:08 +01:00
#REMOVEME? debug_enabled=$(ynh_app_setting_get --app="$app" --key=debug_enabled)
2023-05-26 19:09:08 +02:00
if [ -z "$debug_enabled" ]; then
debug_enabled="0"
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
fi
2024-01-18 13:19:08 +01:00
#REMOVEME? log_level=$(ynh_app_setting_get --app="$app" --key=log_level)
2023-05-26 19:09:08 +02:00
if [ -z "$log_level" ]; then
log_level="WARNING"
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
fi
2024-01-18 13:19:08 +01:00
#REMOVEME? admin_email=$(ynh_app_setting_get --app="$app" --key=admin_email)
2023-05-26 19:09:08 +02:00
if [ -z "$admin_email" ]; then
admin_email="${admin}@${domain}"
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
2023-05-26 19:09:08 +02:00
fi
2024-01-18 13:19:08 +01:00
#REMOVEME? default_from_email=$(ynh_app_setting_get --app="$app" --key=default_from_email)
2023-05-26 19:09:08 +02: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"
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=40
# Backup the current version of the app
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
2023-05-26 19:09:08 +02:00
# restore it if the upgrade fails
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_restore_upgradebackup
2023-05-26 19:09:08 +02:00
}
# Exit if an error occurs during the execution of the script
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_abort_if_errors
2023-05-26 19:09:08 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5
ynh_systemd_action --service_name="$app" --action="stop"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config
# https://yunohost.org/en/contribute/packaging_apps/helpers
# https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx
ynh_add_nginx_config "public_path" "port"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Update dependencies
#=================================================
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=20
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
2023-05-26 19:09:08 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..."
2023-05-26 19:09:08 +02:00
# Create a system user
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_system_user_create --username="$app" --home_dir="$install_dir" --use_shell
2023-05-26 19:09:08 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5
ynh_add_systemd_config --service="$app" --template="systemd.service"
#=================================================
# PYTHON VIRTUALENV
#=================================================
ynh_script_progression --message="Recreate Python virtualenv..." --weight=5
# Always recreate everything fresh with current python version
2024-01-18 13:19:08 +01:00
ynh_secure_remove "${install_dir}/venv"
2023-05-26 19:09:08 +02:00
# Skip pip because of: https://github.com/YunoHost/issues/issues/1960
2024-01-18 13:19:08 +01:00
python3 -m venv --without-pip "${install_dir}/venv"
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
cp ../conf/requirements.txt "$install_dir/requirements.txt"
chown -R "$app:" "$install_dir"
2023-05-26 19:09:08 +02:00
#=================================================
# PIP INSTALLATION
#=================================================
ynh_script_progression --message="Install project via pip..." --weight=45
#run source in a 'sub shell'
(
set +o nounset
2024-01-18 13:19:08 +01:00
source "${install_dir}/venv/bin/activate"
2023-05-26 19:09:08 +02:00
set -o nounset
2024-01-18 13:19:08 +01:00
ynh_exec_as $app $install_dir/venv/bin/python3 -m ensurepip
ynh_exec_as $app $install_dir/venv/bin/pip3 install --upgrade wheel pip setuptools
ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-deps -r "$install_dir/requirements.txt"
2023-05-26 19:09:08 +02:00
)
#=================================================
# copy config files
# ================================================
ynh_script_progression --message="Create project configuration files..."
2024-01-18 13:19:08 +01:00
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
ynh_add_config --template="manage.py" --destination="$install_dir/manage.py"
chmod +x "$install_dir/manage.py"
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +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"
2023-05-26 19:09:08 +02:00
#=================================================
# MIGRATE PYINVENTORY
#=================================================
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10
2024-01-18 13:19:08 +01:00
cd "$install_dir" || exit
2023-05-26 19:09:08 +02:00
# Just for debugging:
./manage.py diffsettings
./manage.py migrate --no-input
./manage.py collectstatic --no-input
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
# Check the configuration
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
./manage.py check --deploy || true
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2023-05-31 18:38:14 +02:00
yunohost service add $app --description="Digital signage system for high schools" --log="${log_file}"
2023-05-26 19:09:08 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R "$app:" "$log_path"
chown -R "$app:www-data" "$public_path"
2024-01-18 13:19:08 +01:00
chown -R "$app:" "$install_dir"
2023-05-26 19:09:08 +02:00
chmod o-rwx "$log_path"
chmod o-rwx "$public_path"
2024-01-18 13:19:08 +01:00
chmod o-rwx "$install_dir"
2023-05-26 19:09:08 +02:00
#=================================================
# Start the app server via systemd
#=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# RELOAD NGINX
#=================================================
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
2023-05-26 19:09:08 +02:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last