2015-05-01 14:30:09 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-01 17:14:15 +02:00
|
|
|
source _common.sh
|
2017-03-18 19:14:28 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
# BUILD VENV
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
ynh_script_progression --message="Building venv..." --weight=6
|
2015-05-01 14:30:09 +02:00
|
|
|
|
2023-06-10 21:45:19 +02:00
|
|
|
__ynh_python_venv_setup --venv_dir="$install_dir/venv" --packages "${pip_dependencies[*]}"
|
|
|
|
python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv")
|
2021-05-21 01:10:01 +02:00
|
|
|
|
2023-06-10 21:45:19 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2022-06-14 00:13:19 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
## Needs $python_venv_site_packages
|
|
|
|
ynh_add_nginx_config
|
2015-05-02 17:28:58 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
# ADD A CONFIGURATION
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
2022-06-14 00:13:19 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
2015-05-02 12:47:52 +02:00
|
|
|
|
2023-06-10 22:38:45 +02:00
|
|
|
# Secret key for cookies encryption.
|
|
|
|
secret_key=$(ynh_string_random --length=32)
|
|
|
|
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
|
|
|
|
|
2022-06-14 00:13:19 +02:00
|
|
|
#run source in a 'sub shell'
|
|
|
|
(
|
|
|
|
set +o nounset
|
2023-06-10 21:45:19 +02:00
|
|
|
source "${install_dir}/venv/bin/activate"
|
2022-06-14 00:13:19 +02:00
|
|
|
set -o nounset
|
2023-06-10 21:45:19 +02:00
|
|
|
python3 ../conf/hash_generator.py $password > ${install_dir}/key.txt
|
2022-06-14 00:13:19 +02:00
|
|
|
)
|
2017-06-19 14:48:19 +02:00
|
|
|
|
2023-06-10 22:38:45 +02:00
|
|
|
hashed_password=$(cat "$install_dir/key.txt")
|
|
|
|
ynh_secure_remove --file="$install_dir/key.txt"
|
|
|
|
ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password
|
2022-06-14 00:13:19 +02:00
|
|
|
|
2023-06-10 21:45:19 +02:00
|
|
|
ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
|
|
|
|
chmod 640 "$install_dir/gunicorn.conf.py"
|
|
|
|
chown $app:$app "$install_dir/gunicorn.conf.py"
|
2021-05-21 01:10:01 +02:00
|
|
|
|
|
|
|
# Allows to comment some config lines if not using sub path
|
2023-06-10 21:45:19 +02:00
|
|
|
sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)"
|
2021-05-21 01:10:01 +02:00
|
|
|
|
2023-06-10 21:45:19 +02:00
|
|
|
ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
|
|
|
|
chmod 640 "$install_dir/ihatemoney.cfg"
|
|
|
|
chown $app:$app "$install_dir/ihatemoney.cfg"
|
2021-05-21 01:10:01 +02:00
|
|
|
|
2023-06-12 16:53:23 +02:00
|
|
|
# Configure log directory
|
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
|
2021-12-16 19:41:08 +01:00
|
|
|
yunohost service add $app --description="$app daemon for IHateMoney" --log=systemd
|
2021-05-21 01:10:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# Start a systemd service
|
2023-09-05 14:01:32 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --line_match="Listening at"
|
2023-06-10 23:09:04 +02:00
|
|
|
wait_gunicorn_start
|
2017-06-20 16:25:41 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2018-07-08 01:27:18 +02:00
|
|
|
|
2021-05-21 01:10:01 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|