1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mygpo_ynh.git synced 2024-09-03 19:55:52 +02:00
mygpo_ynh/scripts/install

107 lines
4.1 KiB
Text
Raw Normal View History

2014-10-20 18:55:53 +02:00
#!/bin/bash
2017-06-02 18:23:51 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
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 16:37:46 +01:00
ynh_app_setting_set --app="$app" --key="secret_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 20:50:00 +01:00
ynh_setup_source --dest_dir="$install_dir/sources"
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 15:49:24 +01:00
mkdir -p "$env_path"
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
2024-03-04 15:43:53 +01:00
set_permissions
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
set_up_virtualenv
2021-03-15 01:36:28 +01:00
2023-02-21 13:51:44 +01:00
ynh_script_progression --message="Collecting static..."
collect_static
2017-06-02 18:23:51 +02:00
#=================================================
2021-03-15 01:36:28 +01:00
# INITIALIZE DATABASE
#=================================================
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"
initialize_db
2017-06-02 18:23:51 +02:00
2024-03-04 15:49:24 +01:00
set_permissions
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
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
#=================================================
2021-03-15 01:36:28 +01:00
ynh_script_progression --message="Installation of $app completed" --last