2022-04-02 17:44:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
# INITIALIZE AND STORE SETTINGS
|
2022-04-02 17:44:57 +02:00
|
|
|
#=================================================
|
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
admin_email="$(ynh_user_get_info "$admin" mail)"
|
|
|
|
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
|
2022-08-16 09:47:54 +02:00
|
|
|
|
2022-04-02 17:44:57 +02:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
2022-08-16 09:47:54 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
|
|
|
|
|
|
#-------------------------------------------------
|
|
|
|
# config_panel.toml settings:
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
debug_enabled="0"
|
2022-08-16 09:47:54 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
|
2024-03-28 22:18:52 +01:00
|
|
|
log_level="WARNING"
|
2022-08-16 09:47:54 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
|
2024-03-28 22:18:52 +01:00
|
|
|
default_from_email="${app}@${domain}"
|
2022-08-16 09:47:54 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from_email"
|
2022-05-18 18:11:49 +02:00
|
|
|
|
2022-04-02 17:44:57 +02:00
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2022-04-02 17:44:57 +02:00
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
mkdir -p "$install_dir/"{app,public/media,public/static}
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_add_config --template="requirements.txt" --destination="$install_dir/app/requirements.txt"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/app/gunicorn.conf.py"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_add_config --template="manage.py" --destination="$install_dir/app/manage.py"
|
|
|
|
chmod +x "$install_dir/app/manage.py"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_add_config --template="settings.py" --destination="$install_dir/app/settings.py"
|
|
|
|
ynh_add_config --template="setup_user.py" --destination="$install_dir/app/setup_user.py"
|
|
|
|
ynh_add_config --template="urls.py" --destination="$install_dir/app/urls.py"
|
|
|
|
ynh_add_config --template="wsgi.py" --destination="$install_dir/app/wsgi.py"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
touch "$install_dir/app/local_settings.py"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
touch "/var/log/$app/$app.log"
|
|
|
|
chown -R "$app:$app" "/var/log/$app"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-08-16 09:47:54 +02:00
|
|
|
# PYTHON VIRTUALENV
|
2022-04-02 17:44:57 +02:00
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_script_progression --message="Installing $app..." --weight=10
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
_venv_install
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
_build_app
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
pushd "$install_dir/app"
|
|
|
|
# Just for debugging:
|
|
|
|
ynh_exec_as "$app" "$venvpy" ./manage.py diffsettings
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_exec_as "$app" "$venvpy" ./manage.py migrate --no-input
|
|
|
|
ynh_exec_as "$app" "$venvpy" ./manage.py collectstatic --no-input
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
|
|
|
|
ynh_exec_as "$app" "$venvpy" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +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.
|
|
|
|
ynh_exec_as "$app" "$venvpy" ./manage.py check --deploy || true
|
|
|
|
popd
|
2022-04-02 17:44:57 +02:00
|
|
|
|
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
# SYSTEM CONFIGURATION
|
2022-04-02 17:44:57 +02:00
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
# Create a dedicated NGINX config using the conf/nginx.conf template
|
|
|
|
ynh_add_nginx_config
|
2022-04-02 19:34:39 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
yunohost service add "$app" --description="Django-fritzconnection server" --log="/var/log/$app/$app.log"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate "$log_file"
|
|
|
|
|
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
# START SYSTEMD SERVICE
|
2022-04-02 17:44:57 +02:00
|
|
|
#=================================================
|
2024-03-28 22:18:52 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
2022-04-02 17:44:57 +02:00
|
|
|
|
2024-03-28 22:18:52 +01:00
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
|
2022-04-02 17:44:57 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|