mirror of
https://github.com/YunoHost-Apps/scovie_ynh.git
synced 2024-09-03 20:16:29 +02:00
119 lines
4.6 KiB
Bash
119 lines
4.6 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression "Ensuring downward compatibility..."
|
|
|
|
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=debug_enabled --value="0"
|
|
if [ -z "${debug_enabled:-}" ]; then
|
|
debug_enabled="0"
|
|
ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
|
|
fi
|
|
|
|
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=log_level --value="WARNING"
|
|
if [ -z "${log_level:-}" ]; then
|
|
log_level="WARNING"
|
|
ynh_app_setting_set --key=log_level --value="$log_level"
|
|
fi
|
|
|
|
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=admin_email --value="${admin}@${domain}"
|
|
if [ -z "${admin_email:-}" ]; then
|
|
admin_email="${admin}@${domain}"
|
|
ynh_app_setting_set --key=admin_email --value="$admin_email"
|
|
fi
|
|
|
|
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=default_from_email --value="${app}@${domain}"
|
|
if [ -z "${default_from_email:-}" ]; then
|
|
default_from_email="${app}@${domain}"
|
|
ynh_app_setting_set --key=default_from_email --value="$default_from_email"
|
|
fi
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression "Stopping systemd service '$app'..."
|
|
|
|
ynh_systemctl --service="$app" --action="stop"
|
|
|
|
#=================================================
|
|
# PIP INSTALLATION
|
|
#=================================================
|
|
ynh_script_progression "Installing project via pip..."
|
|
|
|
# Always recreate everything fresh with current python version
|
|
ynh_safe_rm "$install_dir/venv"
|
|
|
|
_install_scovie_venv
|
|
|
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod o-rwx "$install_dir"
|
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
|
|
#=================================================
|
|
# copy config files
|
|
# ================================================
|
|
ynh_script_progression "Create project configuration files..."
|
|
|
|
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
|
|
|
|
ynh_config_add --template="manage.py" --destination="$install_dir/manage.py"
|
|
chmod +x "$install_dir/manage.py"
|
|
|
|
ynh_config_add --template="settings.py" --destination="$install_dir/settings.py"
|
|
ynh_config_add --template="setup_user.py" --destination="$install_dir/setup_user.py"
|
|
ynh_config_add --template="urls.py" --destination="$install_dir/urls.py"
|
|
ynh_config_add --template="wsgi.py" --destination="$install_dir/wsgi.py"
|
|
|
|
#=================================================
|
|
# MIGRATE PYINVENTORY
|
|
#=================================================
|
|
ynh_script_progression "migrate/collectstatic/createadmin..."
|
|
|
|
pushd "$install_dir"
|
|
# Just for debugging:
|
|
ynh_exec_as_app "$venvpython" ./manage.py diffsettings
|
|
|
|
ynh_exec_as_app "$venvpython" ./manage.py migrate --no-input
|
|
ynh_exec_as_app "$venvpython" ./manage.py collectstatic --no-input
|
|
|
|
# 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)"
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression "Upgrading system configurations related to $app..."
|
|
|
|
ynh_config_add_nginx
|
|
|
|
ynh_config_add_systemd
|
|
|
|
yunohost service add "$app" --description="Digital signage system for high schools" --log="/var/log/$app/$app.log"
|
|
|
|
ynh_config_add_logrotate
|
|
chmod o-rwx "$log_path"
|
|
chown -R "$app:" "$log_path"
|
|
|
|
#=================================================
|
|
# Start the app server via systemd
|
|
#=================================================
|
|
ynh_script_progression "Starting systemd service '$app'..."
|
|
|
|
ynh_systemctl --service="$app" --action="start"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Upgrade of $app completed"
|