2022-04-29 12:18:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
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)
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_app_setting_set --key=weather_api_provider --value=$weather_api_provider
|
|
|
|
ynh_app_setting_set --key=weather_api_key --value=$weather_api_key
|
2023-11-19 18:41:30 +01:00
|
|
|
|
2024-02-24 10:18:06 +01:00
|
|
|
# Configure redis
|
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_app_setting_set --key=redis_db --value="$redis_db"
|
2024-02-24 10:18:06 +01:00
|
|
|
|
|
|
|
# key for the .env __KEY__
|
|
|
|
key=$(ynh_string_random --length=45 | base64)
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_app_setting_set --key=key --value=$key
|
2023-09-04 16:57:10 +02:00
|
|
|
|
2023-03-05 23:12:21 +01:00
|
|
|
#=================================================
|
|
|
|
# LOGROTATE
|
2023-10-14 14:51:39 +02:00
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Configuring logrotate to manage application logfiles"
|
2023-03-05 23:12:21 +01:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_config_add_logrotate
|
|
|
|
|
2023-03-05 23:12:21 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2023-03-05 22:59:39 +01:00
|
|
|
# CONFIGURE THE INSTALL SCRIPT
|
2023-03-05 21:24:24 +01:00
|
|
|
#=================================================
|
|
|
|
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Setting up source files..."
|
2023-03-05 22:59:39 +01:00
|
|
|
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_config_add --template=".env.production" --destination="$install_dir/.env"
|
2023-03-05 22:35:00 +01:00
|
|
|
|
2023-06-11 23:14:27 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL PYTHON DEPENDENCIES
|
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Installing Python dependencies..."
|
2023-06-11 23:14:27 +02:00
|
|
|
|
2023-08-24 13:53:14 +02:00
|
|
|
if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "armel" ]
|
|
|
|
then
|
2024-06-23 08:56:30 +02:00
|
|
|
# Install rustup if not already installed
|
2023-08-24 13:53:14 +02:00
|
|
|
# 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
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_exec_as_app PATH=$PATH rustup update
|
2023-08-24 13:53:14 +02:00
|
|
|
else
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_exec_as_app bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal'
|
2023-08-24 13:53:14 +02:00
|
|
|
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
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_hide_warnings pip install --upgrade pip wheel toml pyyaml
|
2024-06-23 17:38:15 +02:00
|
|
|
ynh_hide_warnings pip install fittrackee=="$(ynh_app_upstream_version)"
|
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
|
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Initializing database..."
|
|
|
|
|
|
|
|
set -a
|
2023-03-05 22:35:00 +01:00
|
|
|
|
2023-12-26 15:07:37 +01:00
|
|
|
source $install_dir/.env
|
|
|
|
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_hide_warnings $install_dir/venv/bin/ftcli db upgrade
|
2023-03-05 21:24:24 +01:00
|
|
|
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_hide_warnings $install_dir/venv/bin/ftcli users create $admin --email $admin_mail --password $password --lang $language
|
2023-04-13 13:31:17 +02:00
|
|
|
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_hide_warnings $install_dir/venv/bin/ftcli users update $admin --set-admin true
|
2023-04-13 13:31:17 +02:00
|
|
|
|
2023-12-26 15:07:37 +01:00
|
|
|
set +a
|
2023-03-05 22:59:39 +01:00
|
|
|
#=================================================
|
|
|
|
# System Configuration
|
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Adding system configurations related to $app ..."
|
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
|
2023-10-14 14:51:39 +02:00
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Configuring NGINX web server..."
|
2023-02-28 22:27:34 +01:00
|
|
|
|
2023-03-05 20:26:44 +01:00
|
|
|
# Create a dedicated NGINX config
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_config_add_nginx
|
2022-04-29 12:18:34 +02:00
|
|
|
|
2023-03-05 20:26:44 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
2023-10-14 14:51:39 +02:00
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Configuring $app's systemd service..."
|
2023-03-05 20:26:44 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_config_add_systemd --service="${app}" --template="fittrackee.service"
|
|
|
|
ynh_config_add_systemd --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
|
2023-10-14 14:51:39 +02:00
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Integrating service in YunoHost..."
|
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
|
|
|
#=================================================
|
2022-04-29 12:18:34 +02:00
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Starting the systemd services..."
|
2022-04-29 12:18:34 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_systemctl --service="${app}" --action="start"
|
|
|
|
ynh_systemctl --service="${app}_workers" --action="start"
|
2023-02-27 22:48:27 +01:00
|
|
|
|
2022-04-29 12:18:34 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2024-06-23 08:56:30 +02:00
|
|
|
ynh_script_progression "Installation of $app completed"
|