2014-10-20 18:55:53 +02:00
|
|
|
#!/bin/bash
|
2015-10-27 16:03:21 +01:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2022-02-02 21:42:33 +01:00
|
|
|
|
2017-06-05 13:11:48 +02:00
|
|
|
source _common.sh
|
2017-06-02 18:23:51 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2024-03-04 12:04:56 +01:00
|
|
|
# INITIALIZE AND STORE SETTINGS
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
admin_email=$(ynh_user_get_info --username="$admin" --key="mail")
|
2021-03-15 01:36:28 +01:00
|
|
|
secret_key=$(ynh_string_random --length=64)
|
|
|
|
staff_token=$(ynh_string_random --length=64)
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key="random_key" --value="$secret_key"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-03-15 01:36:28 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2024-03-04 15:42:05 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/source"
|
2022-02-02 21:42:33 +01:00
|
|
|
|
|
|
|
set_permissions
|
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2024-03-04 12:04:56 +01:00
|
|
|
# APP INITIAL CONFIGURATION
|
2021-03-15 01:36:28 +01:00
|
|
|
#=================================================
|
2024-03-04 12:04:56 +01:00
|
|
|
ynh_script_progression --message="Adding $app's configuration files..." --weight=1
|
2021-03-15 01:36:28 +01:00
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
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"
|
2021-03-15 01:36:28 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SET UP VIRTUALENV
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2021-03-15 01:36:28 +01:00
|
|
|
ynh_script_progression --message="Initializing Python virtualenv..." --weight=20
|
|
|
|
|
2021-04-27 22:37:37 +02:00
|
|
|
set_up_virtualenv
|
2021-03-15 01:36:28 +01:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2021-03-15 01:36:28 +01:00
|
|
|
# INITIALIZE DATABASE
|
|
|
|
#=================================================
|
2022-02-02 21:42:33 +01:00
|
|
|
ynh_script_progression --message="Initializing database..."
|
|
|
|
|
2024-03-04 12:04:56 +01:00
|
|
|
ynh_psql_execute_as_root --sql="ALTER ROLE $db_user SET statement_timeout = 5000;" --database="$db_name"
|
|
|
|
|
2021-04-27 22:37:37 +02:00
|
|
|
initialize_db
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2024-03-04 12:04:56 +01:00
|
|
|
# SYSTEM CONFIGURATION
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2024-03-04 12:04:56 +01:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2018-06-18 00:58:40 +02:00
|
|
|
ynh_add_systemd_config
|
2024-03-04 12:04:56 +01:00
|
|
|
yunohost service add "$app" --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log"
|
2021-03-15 01:36:28 +01:00
|
|
|
ynh_add_systemd_config --service="$app-celery" --template systemd-celery.service
|
|
|
|
ynh_add_systemd_config --service="$app-beat" --template systemd-beat.service
|
2024-03-04 12:04:56 +01:00
|
|
|
# Some workaround bc ynh_add_system_config doesn't know sockets
|
|
|
|
ynh_add_systemd_config --service="$app-socket" --template systemd.socket
|
2021-03-15 01:36:28 +01:00
|
|
|
systemctl disable "$app-socket.service" --quiet
|
|
|
|
mv "/etc/systemd/system/$app-socket.service" "/etc/systemd/system/$app.socket"
|
|
|
|
systemctl daemon-reload --quiet
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2019-05-02 20:44:22 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-03-04 12:04:56 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd services..." --weight=1
|
2019-05-02 20:44:22 +02:00
|
|
|
|
2021-03-15 01:36:28 +01:00
|
|
|
# Start systemd services
|
2024-03-04 12:04:56 +01:00
|
|
|
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"
|
2019-02-10 15:02:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2022-02-02 21:42:33 +01:00
|
|
|
|
2021-03-15 01:36:28 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|