2023-05-26 19:09:08 +02:00
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2024-01-18 13:19:08 +01:00
# INITIALIZE AND STORE SETTINGS
2023-05-26 19:09:08 +02:00
#=================================================
redis_db=$(ynh_redis_get_free_db)
2024-08-31 02:58:37 +02:00
ynh_app_setting_set --key=redis_db --value="$redis_db"
2023-05-26 19:09:08 +02:00
#-------------------------------------------------
# config_panel.toml settings:
2024-08-31 02:58:37 +02:00
ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --key=log_level --value="$log_level"
ynh_app_setting_set --key=admin_email --value="$admin_email"
ynh_app_setting_set --key=default_from_email --value="$default_from_email"
2023-05-26 19:09:08 +02:00
#=================================================
2024-01-18 13:19:08 +01:00
# INSTALLATION
2023-05-26 19:09:08 +02:00
#=================================================
2024-08-31 02:58:37 +02:00
ynh_script_progression "Installing project via pip..."
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
_install_scovie_venv
2023-05-26 19:09:08 +02:00
2024-01-18 14:19:07 +01:00
mkdir -p "$install_dir/public/media" "$install_dir/public/static"
2024-08-31 02:58:37 +02:00
#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"
2024-01-18 13:19:08 +01:00
mkdir -p "$log_path"
touch "$log_file"
2024-01-18 14:19:07 +01:00
2024-01-18 13:19:08 +01:00
chmod o-rwx "$log_path"
chown -R "$app:$app" "$log_path"
2023-05-26 19:09:08 +02:00
#=================================================
2024-01-18 13:19:08 +01:00
# COPY CONFIG FILES
2023-05-26 19:09:08 +02:00
# ================================================
2024-08-31 02:58:37 +02:00
ynh_script_progression "Create $app configuration files..."
2023-05-26 19:09:08 +02:00
2024-08-31 02:58:37 +02:00
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
2023-05-26 19:09:08 +02:00
2024-08-31 02:58:37 +02:00
ynh_config_add --template="manage.py" --destination="$install_dir/manage.py"
2024-01-18 13:19:08 +01:00
chmod +x "$install_dir/manage.py"
2023-05-26 19:09:08 +02:00
2024-08-31 02:58:37 +02:00
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"
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
touch "$install_dir/local_settings.py"
2023-05-26 19:09:08 +02:00
#=================================================
# MIGRATE / COLLECTSTATIC / CREATEADMIN
#=================================================
2024-08-31 02:58:37 +02:00
ynh_script_progression "migrate/collectstatic/createadmin..."
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
pushd "$install_dir"
# Just for debugging:
2024-08-31 02:58:37 +02:00
ynh_exec_as_app "$venvpython" ./manage.py diffsettings
2023-05-26 19:09:08 +02:00
2024-08-31 02:58:37 +02:00
ynh_exec_as_app "$venvpython" ./manage.py migrate --no-input
ynh_exec_as_app "$venvpython" ./manage.py collectstatic --no-input
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
2024-08-31 02:58:37 +02:00
ynh_exec_as_app "$venvpython" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +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.
2024-08-31 02:58:37 +02:00
ynh_exec_as_app "$venvpython" ./manage.py check --deploy || true
2024-01-18 13:19:08 +01:00
popd
2023-05-26 19:09:08 +02:00
#=================================================
2024-01-18 13:19:08 +01:00
# SYSTEM CONFIGURATION
2023-05-26 19:09:08 +02:00
#=================================================
2024-08-31 02:58:37 +02:00
ynh_script_progression "Adding system configurations related to $app..."
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
# Create a dedicated nginx config
2024-08-31 02:58:37 +02:00
ynh_config_add_nginx
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
# Create a dedicated NGINX config using the conf/nginx.conf template
2024-08-31 02:58:37 +02:00
ynh_config_add_systemd
2024-01-18 14:31:54 +01:00
yunohost service add "$app" --description="Digital signage system for high schools" --log="/var/log/$app/$app.log"
2023-05-26 19:09:08 +02:00
2024-01-18 13:19:08 +01:00
# Use logrotate to manage app-specific logfile(s)
2024-08-31 02:58:37 +02:00
ynh_config_add_logrotate "/var/log/$app/$app.log"
2023-05-26 19:09:08 +02:00
#=================================================
# Start the app server via systemd
#=================================================
2024-08-31 02:58:37 +02:00
ynh_script_progression "Starting systemd service $app..."
2023-05-26 19:09:08 +02:00
2024-08-31 02:58:37 +02:00
ynh_systemctl --service="$app" --action="start"
2023-05-26 19:09:08 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2024-08-31 02:58:37 +02:00
ynh_script_progression "Installation of $app completed"