2015-05-01 14:30:09 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
# Constants
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
2015-05-02 17:28:58 +02:00
|
|
|
is_public=$3
|
|
|
|
app=ihatemoney
|
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
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove trailing "/" for next commands
|
|
|
|
path=${path%/}
|
|
|
|
|
2015-05-02 17:28:58 +02:00
|
|
|
# Save app settings
|
|
|
|
sudo yunohost app setting $app domain -v $domain
|
|
|
|
sudo yunohost app setting $app is_public -v "$is_public"
|
2015-05-02 12:47:27 +02:00
|
|
|
|
2015-05-01 14:30:09 +02:00
|
|
|
# Install debian packages dependencies
|
2015-05-02 12:44:41 +02:00
|
|
|
sudo apt-get install -y -qq python-dev python-virtualenv supervisor
|
2015-05-01 14:30:09 +02:00
|
|
|
|
|
|
|
# Create the dedicated user
|
|
|
|
sudo useradd ihatemoney -d /opt/yunohost/ihatemoney/
|
|
|
|
|
|
|
|
# Prepare venv
|
|
|
|
sudo virtualenv /opt/yunohost/ihatemoney/venv
|
|
|
|
sudo /opt/yunohost/ihatemoney/venv/bin/pip install -r ../sources/budget/requirements.txt
|
2015-05-02 12:44:41 +02:00
|
|
|
sudo /opt/yunohost/ihatemoney/venv/bin/pip install gunicorn>=19.3.0 MySQL-python
|
2015-05-01 14:30:09 +02:00
|
|
|
|
|
|
|
# Install source
|
|
|
|
sudo cp -r ../sources/ /opt/yunohost/ihatemoney/src/
|
|
|
|
sudo find /opt/yunohost/ihatemoney/src/ -type f | while read LINE; do sudo chmod 640 "$LINE" ; done
|
2015-05-02 12:45:36 +02:00
|
|
|
sudo find /opt/yunohost/ihatemoney/src/ -type d | while read LINE; do sudo chmod 755 "$LINE" ; done
|
2015-05-01 14:30:09 +02:00
|
|
|
sudo chown -R ihatemoney:ihatemoney /opt/yunohost/ihatemoney/src
|
2015-05-02 12:45:36 +02:00
|
|
|
sudo chown -R www-data:www-data /opt/yunohost/ihatemoney/src/budget/static
|
2015-05-01 14:30:09 +02:00
|
|
|
|
|
|
|
# Create various dirs
|
|
|
|
sudo install -o ihatemoney -g ihatemoney -m 755 \
|
|
|
|
-d /var/log/ihatemoney /etc/ihatemoney /var/run/ihatemoney/
|
|
|
|
|
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
|
|
|
|
sudo install -o root -g root -m 644 \
|
|
|
|
../conf/supervisord.conf /etc/supervisor/conf.d/ihatemoney.conf
|
|
|
|
sudo yunohost service add supervisor
|
|
|
|
|
|
|
|
# Configure database
|
|
|
|
db_pwd=`sudo yunohost app initdb $db_user`
|
2015-05-02 17:28:58 +02:00
|
|
|
sudo yunohost app setting $app mysqlpwd -v $db_pwd
|
2015-05-01 14:30:09 +02:00
|
|
|
|
|
|
|
# Configure ihatemoney
|
2015-05-02 12:47:52 +02:00
|
|
|
sed -i "s@MY_SECRET_KEY@$secret_key@" ../conf/settings.py
|
2015-05-01 14:30:09 +02:00
|
|
|
sed -i "s/MY_EMAIL/$mails_sender/" ../conf/settings.py
|
2015-05-02 12:47:52 +02:00
|
|
|
sed -i "s@MY_MYSQL_PW@$db_pwd@" ../conf/settings.py
|
2015-05-01 23:27:08 +02:00
|
|
|
sed -i "s@MY_PATH@$path@" ../conf/settings.py
|
2015-05-01 14:30:09 +02:00
|
|
|
sudo install -o ihatemoney -g ihatemoney -m 640 \
|
|
|
|
../conf/settings.py /etc/ihatemoney/settings.py
|
|
|
|
# The settings have to be stored here (on python path)
|
|
|
|
sudo ln -s /etc/ihatemoney/settings.py /opt/yunohost/ihatemoney/src/budget/settings.py
|
|
|
|
|
2015-05-02 17:28:58 +02:00
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
|
|
|
sudo yunohost app setting $app unprotected_uris -v "/"
|
|
|
|
fi
|
|
|
|
|
2015-05-01 14:30:09 +02:00
|
|
|
# Configure Nginx and reload
|
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
|
|
|
sudo install -o root -g root -m644 \
|
|
|
|
../conf/nginx.conf /etc/nginx/conf.d/$domain.d/ihatemoney.conf
|
|
|
|
sudo service nginx reload
|
2015-05-02 12:47:52 +02:00
|
|
|
|
|
|
|
# Start backend
|
|
|
|
sudo service supervisor restart
|
|
|
|
|
|
|
|
# Reconfigure sso
|
|
|
|
sudo yunohost app ssowatconf
|