2015-05-01 14:30:09 +02:00
|
|
|
#!/bin/bash
|
2017-03-18 19:12:51 +01:00
|
|
|
set -eu
|
2015-05-01 14:30:09 +02:00
|
|
|
|
2017-03-18 19:14:28 +01:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2015-05-01 14:30:09 +02:00
|
|
|
# Retrieve arguments
|
2017-03-18 19:14:28 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2015-05-02 17:28:58 +02:00
|
|
|
app=ihatemoney
|
2015-05-01 14:30:09 +02:00
|
|
|
|
2017-06-17 17:28:57 +02:00
|
|
|
# Source local utils
|
|
|
|
source _common.sh
|
|
|
|
|
2017-06-18 17:11:10 +02:00
|
|
|
path=$(ynh_normalize_url_path $path)
|
|
|
|
|
2017-03-18 19:14:28 +01:00
|
|
|
# Database settings
|
|
|
|
db_pwd=$(ynh_string_random)
|
|
|
|
db_name=$app
|
|
|
|
db_user=$app
|
|
|
|
|
2015-05-01 14:30:09 +02:00
|
|
|
# Constant arguments
|
|
|
|
db_user=ihatemoney
|
|
|
|
secret_key=`openssl rand -base64 32`
|
|
|
|
mails_sender="no-reply@${domain}"
|
|
|
|
|
|
|
|
sudo yunohost app checkurl $domain$path -a ihatemoney
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2017-03-18 19:14:28 +01:00
|
|
|
ynh_die "${domain}${path} is not available"
|
2015-05-01 14:30:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2015-07-26 18:23:54 +02:00
|
|
|
# Configure database
|
2017-03-18 19:14:28 +01:00
|
|
|
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
|
|
|
|
ynh_app_setting_set $app mysqlpwd $db_pwd
|
2015-07-26 18:23:54 +02:00
|
|
|
|
|
|
|
# Delete db, user dirs and conf if exit with an error
|
|
|
|
# inspired from https://github.com/Kloadut/owncloud_ynh/blob/master/scripts/install#L37
|
|
|
|
|
|
|
|
function exit_properly
|
|
|
|
{
|
|
|
|
set +e
|
2017-06-19 01:59:53 +02:00
|
|
|
ynh_mysql_drop_db $db_name
|
|
|
|
ynh_mysql_drop_user $db_user
|
2015-07-26 18:23:54 +02:00
|
|
|
sudo userdel ihatemoney
|
|
|
|
sudo rm -Rf /opt/yunohost/ihatemoney
|
|
|
|
sudo rm -Rf /etc/ihatemoney
|
|
|
|
sudo rm /etc/nginx/conf.d/$domain.d/ihatemoney.conf
|
|
|
|
sudo rm /etc/supervisor/conf.d/ihatemoney.conf
|
2017-03-18 19:14:28 +01:00
|
|
|
ynh_die "Install script failed, aborted and rolled back the installation"
|
2015-07-26 18:23:54 +02:00
|
|
|
}
|
|
|
|
trap exit_properly ERR
|
|
|
|
|
2015-05-02 17:28:58 +02:00
|
|
|
# Save app settings
|
2017-03-18 19:14:28 +01:00
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app is_public "$is_public"
|
2015-05-02 12:47:27 +02:00
|
|
|
|
2017-06-19 09:35:17 +02:00
|
|
|
install_apt_dependencies
|
2017-06-17 11:11:23 +02:00
|
|
|
|
2017-06-19 09:35:17 +02:00
|
|
|
create_unix_user
|
2017-06-17 00:22:16 +02:00
|
|
|
|
2015-05-01 14:30:09 +02:00
|
|
|
# Prepare venv
|
2018-02-17 00:20:10 +01:00
|
|
|
init_virtualenv
|
2018-07-08 01:28:26 +02:00
|
|
|
sudo /opt/yunohost/ihatemoney/venv/bin/pip install \
|
|
|
|
'gunicorn>=19.3.0' \
|
|
|
|
'PyMySQL>=0.9,<0.10' \
|
|
|
|
'ihatemoney>=2,<3' \
|
2015-05-01 14:30:09 +02:00
|
|
|
|
2017-06-19 09:35:17 +02:00
|
|
|
create_system_dirs
|
2015-05-01 14:30:09 +02:00
|
|
|
|
2015-05-02 12:47:52 +02:00
|
|
|
# Configure gunicorn
|
|
|
|
sudo install -o ihatemoney -g ihatemoney -m 644 \
|
|
|
|
../conf/gunicorn.conf.py /etc/ihatemoney/gunicorn.conf.py
|
|
|
|
|
2015-05-01 14:30:09 +02:00
|
|
|
# Configure supervisor
|
2018-06-24 01:24:15 +02:00
|
|
|
configure_supervisor
|
2018-07-08 01:30:18 +02:00
|
|
|
# In case it was already installed before,
|
|
|
|
# so that it picks /etc/supervisor/conf.d/ihatemoney.conf:
|
|
|
|
supervisorctl update
|
2015-05-01 14:30:09 +02:00
|
|
|
sudo yunohost service add supervisor
|
|
|
|
|
|
|
|
# Configure ihatemoney
|
2017-06-21 13:30:48 +02:00
|
|
|
sed -i "s@MY_SECRET_KEY@$secret_key@" ../conf/ihatemoney.cfg
|
|
|
|
sed -i "s/MY_EMAIL/$mails_sender/" ../conf/ihatemoney.cfg
|
|
|
|
sed -i "s@MY_MYSQL_PW@$db_pwd@" ../conf/ihatemoney.cfg
|
|
|
|
sed -i "s@MY_PATH@$path@" ../conf/ihatemoney.cfg
|
2017-06-19 01:20:59 +02:00
|
|
|
# Remove the conf directive if served at root
|
2017-06-21 13:30:48 +02:00
|
|
|
sed -i "/APPLICATION_ROOT='\/'/d" ../conf/ihatemoney.cfg
|
2015-05-01 14:30:09 +02:00
|
|
|
sudo install -o ihatemoney -g ihatemoney -m 640 \
|
2017-06-21 13:30:48 +02:00
|
|
|
../conf/ihatemoney.cfg /etc/ihatemoney/ihatemoney.cfg
|
2015-05-02 17:28:58 +02:00
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
2016-06-18 00:06:53 +02:00
|
|
|
if [[ "$is_public" -ne 0 ]];
|
2015-05-02 17:28:58 +02:00
|
|
|
then
|
2017-03-18 19:14:28 +01:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2015-05-02 17:28:58 +02:00
|
|
|
fi
|
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
# Configure Nginx
|
|
|
|
configure_nginx "$domain" "$path"
|
2015-05-02 12:47:52 +02:00
|
|
|
|
|
|
|
# Start backend
|
|
|
|
sudo service supervisor restart
|
|
|
|
|
2017-06-19 14:48:19 +02:00
|
|
|
# Reconfigure sso
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
2017-06-18 17:13:39 +02:00
|
|
|
# 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
|
2017-06-20 16:25:41 +02:00
|
|
|
|
|
|
|
sudo service nginx reload
|
2018-07-08 01:27:18 +02:00
|
|
|
# If socket not ready after 2 minutes waiting, ihatemoney will not work.
|
|
|
|
test -S /tmp/budget.gunicorn.sock || exit_properly
|
|
|
|
|
|
|
|
|