2015-05-02 16:36:51 +02:00
|
|
|
#!/bin/bash
|
2016-06-18 00:06:53 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2016-06-18 10:36:18 +02:00
|
|
|
|
2017-06-17 00:22:16 +02:00
|
|
|
# The main logic is to
|
|
|
|
# - install in a src-new folder
|
|
|
|
# - upgrade dependencies
|
|
|
|
# - if everything OK, rename src-new to src
|
|
|
|
|
2016-06-18 10:36:18 +02:00
|
|
|
# Installation paths
|
|
|
|
INSTALL_DIR=/opt/yunohost/ihatemoney
|
|
|
|
PIP=${INSTALL_DIR}/venv/bin/pip
|
|
|
|
|
2016-06-18 00:06:53 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
. /usr/share/yunohost/helpers
|
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path=$(ynh_app_setting_get $app path)
|
|
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
2017-06-18 17:14:35 +02:00
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
VENV_PY_VERSION=$(echo ${INSTALL_DIR}/venv/bin/python*.*|sed 's/.*python//')
|
2018-12-18 18:24:07 +01:00
|
|
|
SYSTEM_PY_VERSION=$(readlink /usr/bin/python3|sed s/.*python//)
|
|
|
|
|
2017-06-17 00:22:16 +02:00
|
|
|
# Source local utils
|
|
|
|
source _common.sh
|
|
|
|
|
2018-11-25 18:38:33 +01:00
|
|
|
ynh_clean_setup () {
|
2018-02-17 00:21:07 +01:00
|
|
|
if [ -e /opt/yunohost/ihatemoney/venv-old ]
|
|
|
|
then
|
|
|
|
sudo mv /opt/yunohost/ihatemoney/venv{-old,}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-11-25 18:38:33 +01:00
|
|
|
ynh_abort_if_errors
|
2018-02-17 00:21:07 +01:00
|
|
|
|
2015-05-02 16:36:51 +02:00
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
#----------------------------PRE-UPGRADE MIGRATIONS-----------------------
|
2016-06-18 10:36:18 +02:00
|
|
|
|
2017-06-17 00:22:16 +02:00
|
|
|
|
2017-06-21 13:30:48 +02:00
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
# MIGRATION: upgrade arg to typed boolean form
|
2017-06-21 13:30:48 +02:00
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
if (($is_public != 0)) && (($is_public != 1))
|
|
|
|
then
|
|
|
|
if [ $is_public = "No" ];
|
|
|
|
then
|
|
|
|
is_public=0
|
|
|
|
else
|
|
|
|
is_public=1
|
|
|
|
fi
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
2017-06-21 13:30:48 +02:00
|
|
|
fi
|
|
|
|
|
2018-02-17 00:20:10 +01:00
|
|
|
|
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
# MIGRATION: Switch to a python3 venv
|
|
|
|
if [[ "$VENV_PY_VERSION" == 2.7 ]]
|
2018-02-17 00:20:10 +01:00
|
|
|
then
|
|
|
|
install_apt_dependencies
|
|
|
|
# Trash py2 venv
|
|
|
|
sudo mv ${INSTALL_DIR}/venv ${INSTALL_DIR}/venv-old
|
|
|
|
init_virtualenv
|
|
|
|
|
|
|
|
# Clears all cookie-sessions, because py2 & py3 sessions are incompatible
|
|
|
|
# Relates https://github.com/lepture/flask-wtf/issues/279 (fix unreleased)
|
|
|
|
new_secret_key=`openssl rand -base64 32`
|
2018-06-24 01:24:15 +02:00
|
|
|
sudo sed -i "s/SECRET_KEY = \".*\"/SECRET_KEY = \"${new_secret_key}\"/g" /etc/ihatemoney/ihatemoney.cfg
|
2018-02-17 00:20:10 +01:00
|
|
|
fi
|
|
|
|
|
2015-05-02 16:36:51 +02:00
|
|
|
|
2018-04-02 00:54:39 +02:00
|
|
|
|
2018-12-18 18:24:07 +01:00
|
|
|
# MIGRATION: minor Py version has changed ? rebuilt venv
|
|
|
|
|
|
|
|
# Useful for Py 3.4 → 3.5, Jessie → Stretch, ynh 2.x → 3.x
|
|
|
|
if [[ "$VENV_PY_VERSION" != '2.7' ]] && [[ "$VENV_PY_VERSION" != "$SYSTEM_PY_VERSION" ]]
|
|
|
|
then
|
|
|
|
sudo mv ${INSTALL_DIR}/venv ${INSTALL_DIR}/venv-old
|
|
|
|
init_virtualenv
|
|
|
|
|
|
|
|
# the static path changed
|
|
|
|
configure_nginx "$domain" "$path"
|
|
|
|
fi
|
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
#-------------------------------UPGRADE-------------------------
|
|
|
|
|
|
|
|
|
|
|
|
# Upgrade code and dependencies
|
|
|
|
sudo ${PIP} install --upgrade 'gunicorn>=19.3.0' PyMySQL 'ihatemoney>=2,<3'
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------POST-UPGRADE MIGRATIONS-----------------
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-02 00:54:39 +02:00
|
|
|
|
|
|
|
# Python-MySQL is no longer maintained and does not support Py3
|
|
|
|
sudo sed -i "s@'mysql://@'mysql+pymysql://@g" ${ihatemoney_conf_path}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-24 01:24:15 +02:00
|
|
|
# MIGRATION: Remove old code (from pre-2.x versions, not using pip)
|
|
|
|
|
|
|
|
sudo rm -rf ${INSTALL_DIR}/src
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# MIGRATION: change the static path (from pre-2.x versions, not using pip)
|
|
|
|
|
|
|
|
if grep -q /opt/yunohost/ihatemoney/src/ /etc/nginx/conf.d/${domain}.d/ihatemoney.conf
|
|
|
|
then
|
|
|
|
# the static path changed
|
|
|
|
configure_nginx "$domain" "$path"
|
|
|
|
|
|
|
|
# Supervisor no longer change its directory to src/ dir
|
|
|
|
configure_supervisor
|
|
|
|
supervisorctl update
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# MIGRATION: new-style settings
|
|
|
|
|
|
|
|
if [ -e /etc/ihatemoney/settings.py ]; then
|
|
|
|
# Strip out the no longer used part of the settings
|
|
|
|
sudo python2 -c"d = open('/etc/ihatemoney/settings.py').read().replace('try:\n from settings import *\nexcept ImportError:\n pass\n', ''); open('/etc/ihatemoney/settings.py', 'w').write(d)"
|
|
|
|
# Rename
|
|
|
|
sudo mv /etc/ihatemoney/settings.py ${ihatemoney_conf_path}
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# MIGRATION: Remove no longer used symlink
|
|
|
|
|
|
|
|
# (ihatemoney now read its conf by default from /etc/ihatemoney/ihatemoney.cfg)
|
|
|
|
sudo rm -f ${INSTALL_DIR}/src/budget/settings.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------FINALIZATION-----------------------
|
|
|
|
|
|
|
|
# Everything went ok ? Let's keep this new venv.
|
|
|
|
sudo rm -rf ${INSTALL_DIR}/venv-old
|
|
|
|
|
2015-05-02 16:36:51 +02:00
|
|
|
# Restart backend
|
|
|
|
sudo supervisorctl restart budget
|
2018-06-24 01:24:15 +02:00
|
|
|
|
|
|
|
# Reload nginx conf
|
|
|
|
sudo systemctl reload nginx
|