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

89 lines
2.1 KiB
Text
Raw Normal View History

#!/bin/bash
# Source YunoHost helpers
2020-07-01 17:14:15 +02:00
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
app=ihatemoney
# Database settings
db_pwd=$(ynh_string_random)
db_name=$app
db_user=$app
# Constant arguments
2020-07-01 17:14:15 +02:00
secret_key=$(ynh_string_random --length 32)
mails_sender="no-reply@${domain}"
ynh_abort_if_errors
ynh_webpath_register $app $domain $path
# Configure database
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
# Save app settings
2020-07-01 17:14:15 +02:00
ynh_app_setting_set "$app" mysqlpwd "$db_pwd"
ynh_app_setting_set "$app" is_public "$is_public"
install_apt_dependencies
2017-06-17 11:11:23 +02:00
create_unix_user
# Prepare venv
init_virtualenv
pip_install
create_system_dirs
2015-05-02 12:47:52 +02:00
# Configure gunicorn
2020-07-01 17:14:15 +02:00
install -o ihatemoney -g ihatemoney -m 644 \
2015-05-02 12:47:52 +02:00
../conf/gunicorn.conf.py /etc/ihatemoney/gunicorn.conf.py
# Configure supervisor
configure_supervisor
# In case it was already installed before,
# so that it picks /etc/supervisor/conf.d/ihatemoney.conf:
supervisorctl update
2020-07-01 17:14:15 +02:00
yunohost service add supervisor
# Configure ihatemoney
2020-07-01 17:14:15 +02:00
ynh_replace_string "MY_SECRET_KEY" "$secret_key" ../conf/ihatemoney.cfg
ynh_replace_string "MY_EMAIL" "$mails_sender" ../conf/ihatemoney.cfg
ynh_replace_string "MY_MYSQL_PW" "$db_pwd" ../conf/ihatemoney.cfg
ynh_replace_string "MY_PATH" "$path" ../conf/ihatemoney.cfg
# Remove the conf directive if served at root
sed -i "/APPLICATION_ROOT='\/'/d" ../conf/ihatemoney.cfg
2020-07-01 17:14:15 +02:00
install -o ihatemoney -g ihatemoney -m 640 \
../conf/ihatemoney.cfg /etc/ihatemoney/ihatemoney.cfg
# If app is public, add url to SSOWat conf as skipped_uris
if [[ "$is_public" -ne 0 ]];
then
ynh_app_setting_set $app unprotected_uris "/"
fi
# Configure Nginx
configure_nginx "$domain" "$path"
2015-05-02 12:47:52 +02:00
# Start backend
2020-07-01 17:14:15 +02:00
systemctl start supervisor
# Wait that gunicorn is ready to consider the install finished, that is to
# avoid HTTP 502 right after installation
for i in `seq 1 120`
do
test -S /tmp/budget.gunicorn.sock && break
sleep 1
done
# If socket not ready after 2 minutes waiting, ihatemoney will not work.
2020-07-01 17:14:15 +02:00
test -S /tmp/budget.gunicorn.sock || ynh_die
2020-07-01 17:14:15 +02:00
systemctl reload nginx