#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # INITIALIZE AND STORE SETTINGS #================================================= admin_email=$(ynh_user_get_info --username="$admin" --key="mail") secret_key=$(ynh_string_random --length=64) staff_token=$(ynh_string_random --length=64) ynh_app_setting_set --app="$app" --key="secret_key" --value="$secret_key" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/sources" #================================================= # APP INITIAL CONFIGURATION #================================================= ynh_script_progression --message="Adding $app's configuration files..." --weight=1 mkdir -p "$env_path" echo "$admin <$admin_email>" > "$env_path/ADMINS" echo "None" > "$env_path/BROKER_POOL_LIMIT" echo "redis://localhost:6379" > "$env_path/BROKER_URL" echo "postgres://$db_user:$db_pwd@localhost:5432/$db_name" > "$env_path/DATABASE_URL" echo "False" > "$env_path/DEBUG" echo "$domain" > "$env_path/DEFAULT_BASE_URL" echo "$app@$domain" > "$env_path/DEFAULT_FROM_EMAIL" echo "django.core.mail.backends.console.EmailBackend" > "$env_path/EMAIL_BACKEND" echo "$data_dir" > "$env_path/MEDIA_ROOT" echo "$secret_key" > "$env_path/SECRET_KEY" echo "$app@$domain" > "$env_path/SERVER_EMAIL" echo "$staff_token" > "$env_path/STAFF_TOKEN" set_permissions #================================================= # SET UP VIRTUALENV #================================================= ynh_script_progression --message="Initializing Python virtualenv..." --weight=20 set_up_virtualenv ynh_script_progression --message="Collecting static..." collect_static #================================================= # INITIALIZE DATABASE #================================================= ynh_script_progression --message="Initializing database..." ynh_psql_execute_as_root --sql="ALTER ROLE $db_user SET statement_timeout = 5000;" --database="$db_name" initialize_db set_permissions #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config yunohost service add "$app" --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" ynh_add_systemd_config --service="$app-celery" --template systemd-celery.service ynh_add_systemd_config --service="$app-beat" --template systemd-beat.service # Some workaround bc ynh_add_system_config doesn't know sockets ynh_add_systemd_config --service="$app-socket" --template systemd.socket systemctl disable "$app-socket.service" --quiet mv "/etc/systemd/system/$app-socket.service" "/etc/systemd/system/$app.socket" systemctl daemon-reload --quiet #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting $app's systemd services..." --weight=1 # Start systemd services ynh_systemd_action --service_name="$app.socket" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last