2022-04-29 12:18:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-04-13 16:05:03 +02:00
|
|
|
admin=$(ynh_user_get_info --username=$admin --key=username)
|
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
|
2023-09-05 14:33:23 +02:00
|
|
|
mail_user=$app
|
2023-09-05 14:26:02 +02:00
|
|
|
mail_password=$mail_pwd
|
|
|
|
mail_domain=$domain
|
2023-09-04 16:57:10 +02:00
|
|
|
|
2023-03-05 23:12:21 +01:00
|
|
|
#=================================================
|
|
|
|
# LOGROTATE
|
|
|
|
ynh_script_progression --message="Configuring logrotate to manage application logfiles" --weight=1
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate --specific_user=$app
|
|
|
|
touch /var/log/$app/$app.log
|
2023-03-08 21:40:21 +01:00
|
|
|
touch /var/log/$app/${app}_workers.log
|
2023-03-08 22:57:32 +01:00
|
|
|
touch /var/log/$app/gunicorn.log
|
2023-03-05 23:12:21 +01:00
|
|
|
chown -R $app:www-data /var/log/$app/
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2023-03-05 21:24:24 +01:00
|
|
|
#=================================================
|
2023-03-05 22:59:39 +01:00
|
|
|
# CONFIGURE THE INSTALL SCRIPT
|
2023-03-05 21:24:24 +01:00
|
|
|
#=================================================
|
|
|
|
|
2023-03-05 22:59:39 +01:00
|
|
|
# key for the .env __KEY__
|
|
|
|
key=$(ynh_string_random --length=45 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=key --value=$key
|
2023-03-05 21:24:24 +01:00
|
|
|
|
2023-03-05 23:12:21 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=64
|
2023-03-05 22:59:39 +01:00
|
|
|
|
2023-03-05 23:33:24 +01:00
|
|
|
ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env"
|
|
|
|
chmod 600 $install_dir/.env
|
|
|
|
|
2023-03-05 22:59:39 +01:00
|
|
|
chown -R $app:www-data "$install_dir"
|
2023-03-05 22:35:00 +01:00
|
|
|
|
2023-03-05 23:33:24 +01:00
|
|
|
set -a; source "$install_dir/.env"; set +a
|
|
|
|
|
2023-06-11 23:14:27 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL PYTHON DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing Python dependencies..." --weight=3
|
|
|
|
|
2023-08-24 13:53:14 +02:00
|
|
|
if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "armel" ]
|
|
|
|
then
|
|
|
|
# Install rustup is not already installed
|
|
|
|
# We need this to be able to install cryptgraphy on ARM hardware
|
|
|
|
export PATH="$PATH:$install_dir/.cargo/bin:$install_dir/.local/bin:/usr/local/sbin"
|
|
|
|
if [ -e $install_dir/.rustup ]; then
|
|
|
|
sudo -u "$app" env PATH=$PATH rustup update
|
|
|
|
else
|
|
|
|
sudo -u "$app" bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal'
|
|
|
|
fi
|
|
|
|
|
2023-08-25 11:58:51 +02:00
|
|
|
fi
|
|
|
|
|
2023-03-05 22:59:39 +01:00
|
|
|
pushd $install_dir
|
2023-06-11 23:14:27 +02:00
|
|
|
python3 -m venv $install_dir/venv
|
|
|
|
source $install_dir/venv/bin/activate
|
2023-08-25 11:31:21 +02:00
|
|
|
ynh_exec_warn_less pip install --upgrade pip
|
2023-06-11 23:36:29 +02:00
|
|
|
ynh_exec_warn_less pip install fittrackee==$fittrackee_version toml pyyaml
|
2023-03-05 22:59:39 +01:00
|
|
|
popd
|
2023-02-27 22:48:27 +01:00
|
|
|
|
2023-03-05 21:24:24 +01:00
|
|
|
#=================================================
|
|
|
|
# INITIALIZE DATABASE
|
|
|
|
#=================================================
|
2023-03-05 23:56:24 +01:00
|
|
|
ynh_script_progression --message="Initializing database..." --weight=1
|
2023-03-05 22:35:00 +01:00
|
|
|
|
2023-06-11 23:14:27 +02:00
|
|
|
ynh_exec_warn_less $install_dir/venv/bin/ftcli db upgrade
|
2023-03-05 21:24:24 +01:00
|
|
|
|
2023-06-11 23:14:27 +02:00
|
|
|
ynh_exec_warn_less $install_dir/venv/bin/ftcli users create $admin --email $admin_mail --password $password
|
2023-04-13 13:31:17 +02:00
|
|
|
|
2023-06-11 23:14:27 +02:00
|
|
|
ynh_exec_warn_less $install_dir/venv/bin/ftcli users update $admin --set-admin true
|
2023-04-13 13:31:17 +02:00
|
|
|
|
2023-03-05 22:59:39 +01:00
|
|
|
#=================================================
|
|
|
|
# System Configuration
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Adding system configurations related to $app ..." --weight=1
|
2023-03-05 20:26:44 +01:00
|
|
|
|
2023-02-28 22:27:34 +01:00
|
|
|
#=================================================
|
2023-03-05 20:26:44 +01:00
|
|
|
# NGINX CONFIGURATION
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
2023-02-28 22:27:34 +01:00
|
|
|
|
2023-03-05 20:26:44 +01:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2022-04-29 12:18:34 +02:00
|
|
|
|
2023-03-05 20:26:44 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config --service="${app}" --template="fittrackee.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_workers" --template="fittrackee_workers.service"
|
2023-03-03 16:10:09 +01:00
|
|
|
|
2023-03-05 20:26:44 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2023-03-03 17:42:30 +01:00
|
|
|
|
2023-09-04 20:14:01 +02:00
|
|
|
yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log"
|
2023-03-08 21:40:21 +01:00
|
|
|
yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log"
|
2023-03-03 17:42:30 +01:00
|
|
|
|
2023-03-05 22:59:39 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
2023-03-06 08:30:23 +01:00
|
|
|
|
2023-03-06 07:46:21 +01:00
|
|
|
|
2022-04-29 12:18:34 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-03-05 22:59:39 +01:00
|
|
|
ynh_script_progression --message="Starting the systemd services..." --weight=15
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2023-03-09 13:38:15 +01:00
|
|
|
ynh_systemd_action --service_name="${app}" --action="start"
|
|
|
|
ynh_systemd_action --service_name="${app}_workers" --action="start"
|
2023-02-27 22:48:27 +01:00
|
|
|
|
2022-04-29 12:18:34 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2023-03-05 23:31:02 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|