2020-12-23 19:53:13 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
|
|
|
|
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
2022-08-14 17:13:32 +02:00
|
|
|
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
2020-12-23 19:53:13 +01:00
|
|
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
|
|
|
log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app="$app" --key=path)
|
|
|
|
|
|
|
|
port=$(ynh_app_setting_get --app="$app" --key=port)
|
2022-08-14 13:59:26 +02:00
|
|
|
|
2020-12-23 19:53:13 +01:00
|
|
|
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
|
2022-08-14 13:59:26 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name="$app")
|
|
|
|
db_user=$db_name
|
|
|
|
|
2020-12-23 19:53:13 +01:00
|
|
|
admin_mail=$(ynh_user_get_info "$admin" mail)
|
|
|
|
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
|
|
|
|
|
2022-08-14 19:30:06 +02:00
|
|
|
debug_enabled=$(ynh_app_setting_get --app="$app" --key=debug_enabled)
|
|
|
|
if [ -z "$debug_enabled" ]; then
|
|
|
|
debug_enabled="0"
|
|
|
|
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
|
|
|
|
fi
|
2022-08-14 13:59:26 +02:00
|
|
|
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=40
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping systemd services..." --weight=5
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
#=================================================
|
|
|
|
# Manage old settings
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Always deactivate settings.DEBUG:
|
2022-08-14 19:30:06 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=debug_enabled --value="False"
|
2022-08-14 13:59:26 +02:00
|
|
|
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..."
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2022-08-14 17:49:27 +02:00
|
|
|
# https://yunohost.org/en/contribute/packaging_apps/helpers
|
|
|
|
# https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx
|
2022-08-14 17:13:32 +02:00
|
|
|
ynh_add_nginx_config "public_path" "port"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# Update dependencies
|
|
|
|
#=================================================
|
2022-01-19 09:11:54 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=20
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
2022-08-14 14:26:16 +02:00
|
|
|
ynh_add_systemd_config --service="$app" --template="systemd.service"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-08-14 19:30:06 +02:00
|
|
|
# PYTHON VIRTUALENV
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2022-08-14 19:30:06 +02:00
|
|
|
ynh_script_progression --message="Recreate Python virtualenv..." --weight=5
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-01-19 09:10:45 +01:00
|
|
|
# Always recreate everything fresh with current python version
|
|
|
|
ynh_secure_remove "${final_path}/venv"
|
|
|
|
|
|
|
|
# Skip pip because of: https://github.com/YunoHost/issues/issues/1960
|
|
|
|
python3 -m venv --without-pip "${final_path}/venv"
|
|
|
|
|
2020-12-29 10:53:21 +01:00
|
|
|
cp ../conf/requirements.txt "$final_path/requirements.txt"
|
2021-10-10 12:14:54 +02:00
|
|
|
chown -R "$app:" "$final_path"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 19:30:06 +02:00
|
|
|
#=================================================
|
|
|
|
# PIP INSTALLATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Install project via pip..." --weight=45
|
2020-12-23 19:53:13 +01:00
|
|
|
#run source in a 'sub shell'
|
|
|
|
(
|
2020-12-29 10:53:21 +01:00
|
|
|
set +o nounset
|
|
|
|
source "${final_path}/venv/bin/activate"
|
|
|
|
set -o nounset
|
2022-01-19 09:10:45 +01:00
|
|
|
ynh_exec_as $app $final_path/venv/bin/python3 -m ensurepip
|
|
|
|
ynh_exec_as $app $final_path/venv/bin/pip3 install --upgrade wheel pip setuptools
|
|
|
|
ynh_exec_as $app $final_path/venv/bin/pip3 install --no-deps -r "$final_path/requirements.txt"
|
2020-12-23 19:53:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# copy config files
|
|
|
|
# ================================================
|
2020-12-29 10:51:43 +01:00
|
|
|
ynh_script_progression --message="Create project configuration files..."
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
ynh_add_config --template="gunicorn.conf.py" --destination="$final_path/gunicorn.conf.py"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
ynh_add_config --template="manage.py" --destination="$final_path/manage.py"
|
2020-12-23 19:53:13 +01:00
|
|
|
chmod +x "$final_path/manage.py"
|
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
ynh_add_config --template="settings.py" --destination="$final_path/settings.py"
|
|
|
|
ynh_add_config --template="setup_user.py" --destination="$final_path/setup_user.py"
|
|
|
|
ynh_add_config --template="urls.py" --destination="$final_path/urls.py"
|
|
|
|
ynh_add_config --template="wsgi.py" --destination="$final_path/wsgi.py"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-28 10:56:42 +01:00
|
|
|
# MIGRATE PYINVENTORY
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2021-02-28 10:56:42 +01:00
|
|
|
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
cd "$final_path" || exit
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
# Just for debugging:
|
|
|
|
./manage.py diffsettings
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
./manage.py migrate --no-input
|
|
|
|
./manage.py collectstatic --no-input
|
2020-12-29 10:51:43 +01:00
|
|
|
|
2022-08-14 13:59:26 +02:00
|
|
|
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
|
|
|
./manage.py create_superuser --username="$admin" --email="$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
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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..."
|
|
|
|
|
|
|
|
yunohost service add $app --description="Web based management to catalog things" --log="${log_file}"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
2021-10-10 12:14:54 +02:00
|
|
|
chown -R "$app:" "$log_path"
|
2022-08-14 17:13:32 +02:00
|
|
|
chown -R "$app:www-data" "$public_path"
|
2021-10-10 12:14:54 +02:00
|
|
|
chown -R "$app:" "$final_path"
|
2020-12-23 19:53:13 +01:00
|
|
|
|
2022-01-19 09:11:23 +01:00
|
|
|
chmod o-rwx "$log_path"
|
2022-08-14 17:13:32 +02:00
|
|
|
chmod o-rwx "$public_path"
|
2022-01-19 09:11:23 +01:00
|
|
|
chmod o-rwx "$final_path"
|
|
|
|
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2021-02-28 10:56:42 +01:00
|
|
|
# Start django_example_ynh via systemd
|
2020-12-23 19:53:13 +01:00
|
|
|
#=================================================
|
2022-08-14 13:59:26 +02:00
|
|
|
ynh_script_progression --message="Starting django_example_ynh's services..." --weight=5
|
2020-12-23 19:53:13 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|