django-fritzconnection_ynh/scripts/install

157 lines
5.5 KiB
Text
Raw Normal View History

2022-04-02 17:44:57 +02:00
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2024-08-27 20:51:05 +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)
#
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
# SETTINGS
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
ynh_script_progression --message="Storing installation settings..."
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
# Logging:
log_file="/var/log/$app/$app.log"
ynh_app_setting_set --app=$app --key=log_file --value="$log_file"
2022-08-16 09:47:54 +02:00
2024-08-27 20:51:05 +02:00
# Redis:
2022-04-02 17:44:57 +02:00
redis_db=$(ynh_redis_get_free_db)
2024-08-27 20:51:05 +02:00
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
2022-08-16 09:47:54 +02:00
2024-08-27 20:51:05 +02:00
# App settings:
ynh_app_setting_set --app=$app --key=default_from_email --value="$default_from_email"
ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email"
ynh_app_setting_set --app=$app --key=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --app=$app --key=log_level --value="$log_level"
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
mkdir -p "$install_dir/media" "$install_dir/static"
2022-05-18 18:11:49 +02:00
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
# SETUP LOG FILE
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
ynh_script_progression --message="Setup logging..."
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
myynh_setup_log_file
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile="$log_file" --specific_user=$app
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
#=================================================
# PYTHON VIRTUALENV
#=================================================
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45
cp ../conf/requirements.txt "$data_dir/requirements.txt"
myynh_setup_python_venv
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
#=================================================
# copy config files
# ================================================
ynh_script_progression --message="Create $app configuration files..."
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py"
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
ynh_add_config --template="manage.py" --destination="$data_dir/manage.py"
chmod -c +x "$data_dir/manage.py"
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
ynh_add_config --template="settings.py" --destination="$data_dir/settings.py"
ynh_add_config --template="setup_user.py" --destination="$data_dir/setup_user.py"
ynh_add_config --template="urls.py" --destination="$data_dir/urls.py"
ynh_add_config --template="wsgi.py" --destination="$data_dir/wsgi.py"
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
touch "$data_dir/local_settings.py"
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
# MIGRATE / COLLECTSTATIC / CREATEADMIN
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
cd "$data_dir" || exit
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
# Just for debugging:
./manage.py diffsettings
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
./manage.py migrate --no-input
./manage.py collectstatic --no-input
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
# 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)"
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +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
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add --description $app $app
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
# GENERIC FINALIZATION
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Set file permissions..."
myynh_fix_file_permissions
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5
# https://yunohost.org/en/packaging_apps_helpers#ynh-add-systemd-config
# https://github.com/YunoHost/yunohost/blob/dev/helpers/systemd
ynh_add_systemd_config --service=$app --template="systemd.service"
2022-04-02 19:34:39 +02:00
2024-08-27 20:51:05 +02:00
#=================================================
# Start the app server via systemd
#=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file"
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
# NGINX CONFIGURATION
2022-04-02 17:44:57 +02:00
#=================================================
2024-08-27 20:51:05 +02:00
ynh_script_progression --message="Configuring nginx web server..."
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
# 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"
2022-04-02 17:44:57 +02:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last