2020-12-07 16:20:37 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
# Install parameters are automatically saved as settings
|
|
|
|
#
|
|
|
|
# Settings are automatically loaded as bash variables
|
|
|
|
# in every app script context, therefore typically these will exist:
|
|
|
|
# - $domain
|
|
|
|
# - $path
|
|
|
|
# - $language
|
|
|
|
# ... etc
|
|
|
|
#
|
|
|
|
# Resources defined in the manifest are provisioned prior to this script
|
|
|
|
# and corresponding settings are also available, such as:
|
|
|
|
# - $install_dir
|
|
|
|
# - $port
|
|
|
|
# - $db_name
|
|
|
|
# ...
|
|
|
|
|
|
|
|
#
|
|
|
|
# $app is the app id (i.e. 'example' for first install,
|
|
|
|
# or 'example__2', '__3', ... for multi-instance installs)
|
|
|
|
#
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETTINGS
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Storing installation settings..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
# Logging:
|
|
|
|
log_file="/var/log/$app/$app.log"
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_app_setting_set --key=log_file --value="$log_file"
|
2022-09-15 18:16:57 +02:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
# Redis:
|
2020-12-08 09:31:10 +01:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_app_setting_set --key=redis_db --value="$redis_db"
|
2022-09-15 18:16:57 +02:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
# App settings:
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_app_setting_set --key=default_from_email --value="$default_from_email"
|
|
|
|
ynh_app_setting_set --key=admin_email --value="$admin_email"
|
|
|
|
ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
|
|
|
|
ynh_app_setting_set --key=log_level --value="$log_level"
|
2020-12-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-08-22 19:52:36 +02:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Validating installation parameters..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
mkdir -p "$install_dir/media" "$install_dir/static"
|
2020-12-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-08-22 19:52:36 +02:00
|
|
|
# SETUP LOG FILE
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Setup logging..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
myynh_setup_log_file
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
# Use logrotate to manage application logfile(s)
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_config_add_logrotate "$log_file"
|
2020-12-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-09-15 18:16:57 +02:00
|
|
|
# PYTHON VIRTUALENV
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Create and setup Python virtualenv..."
|
2023-08-22 19:52:36 +02:00
|
|
|
cp ../conf/requirements.txt "$data_dir/requirements.txt"
|
|
|
|
myynh_setup_python_venv
|
2020-12-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-12-08 09:31:10 +01:00
|
|
|
# copy config files
|
|
|
|
# ================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Create $app configuration files..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_config_add --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_config_add --template="manage.py" --destination="$data_dir/manage.py"
|
2023-08-22 19:52:36 +02:00
|
|
|
chmod -c +x "$data_dir/manage.py"
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_config_add --template="settings.py" --destination="$data_dir/settings.py"
|
|
|
|
ynh_config_add --template="setup_user.py" --destination="$data_dir/setup_user.py"
|
|
|
|
ynh_config_add --template="urls.py" --destination="$data_dir/urls.py"
|
|
|
|
ynh_config_add --template="wsgi.py" --destination="$data_dir/wsgi.py"
|
2020-12-08 09:31:10 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
touch "$data_dir/local_settings.py"
|
2020-12-09 12:05:24 +01:00
|
|
|
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
|
|
|
# MIGRATE / COLLECTSTATIC / CREATEADMIN
|
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "migrate/collectstatic/createadmin..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
cd "$data_dir" || exit
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2022-07-26 19:50:37 +02:00
|
|
|
# Just for debugging:
|
|
|
|
./manage.py diffsettings
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2022-07-26 19:50:37 +02:00
|
|
|
./manage.py migrate --no-input
|
|
|
|
./manage.py collectstatic --no-input
|
2020-12-29 13:58:40 +01:00
|
|
|
|
2022-07-26 19:50:37 +02:00
|
|
|
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
2022-09-15 18:16:57 +02:00
|
|
|
./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
|
2022-07-26 19:50:37 +02:00
|
|
|
|
|
|
|
# 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-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-12-08 09:31:10 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Integrating service in YunoHost..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
yunohost service add $app
|
2020-12-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Set file permissions..."
|
2023-08-22 19:52:36 +02:00
|
|
|
myynh_fix_file_permissions
|
2022-01-01 14:28:52 +01:00
|
|
|
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2020-12-08 09:31:10 +01:00
|
|
|
# SETUP SYSTEMD
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Configuring systemd service '$app'..."
|
2022-09-15 18:16:57 +02:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
# https://yunohost.org/en/packaging_apps_helpers#ynh-add-systemd-config
|
2022-09-15 18:16:57 +02:00
|
|
|
# https://github.com/YunoHost/yunohost/blob/dev/helpers/systemd
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_config_add_systemd
|
2020-12-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-09-15 18:16:57 +02:00
|
|
|
# Start the app server via systemd
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Starting systemd service '$app'..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_systemctl --service=$app --action="start" --log_path="$log_file"
|
2020-12-07 16:20:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-08-22 19:52:36 +02:00
|
|
|
# NGINX CONFIGURATION
|
2020-12-07 16:20:37 +01:00
|
|
|
#=================================================
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Configuring nginx web server..."
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2023-08-22 19:52:36 +02:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
# https://yunohost.org/en/contribute/packaging_apps/helpers
|
|
|
|
# https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_config_add_nginx "public_path" "port"
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2020-12-09 17:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2020-12-07 16:20:37 +01:00
|
|
|
|
2024-08-31 02:55:33 +02:00
|
|
|
ynh_script_progression "Installation of $app completed"
|