From c114aa6ac805ba960df36f23aa4c8c39f18a1a8d Mon Sep 17 00:00:00 2001 From: Jocelyn Delalande Date: Sat, 17 Jun 2017 00:22:16 +0200 Subject: [PATCH] Use releases tarballs rather than git master. - upgrade to ihatemoney 0.9 - refactor some code into a `_common.sh` --- scripts/_common.sh | 32 ++++++++++++++++++++++++++++++++ scripts/install | 18 ++++++++++-------- scripts/upgrade | 28 +++++++++++++++++++--------- 3 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 scripts/_common.sh diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..68b0aa9 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,32 @@ +fetch_and_extract() { + local DESTDIR=$1 + local OWNER_USER=${2:-admin} + + VERSION=0.9 + SHA256=4dab1018563097b309848de5873d63b913390a66327871b0c958ed8516762870 + SOURCE_URL="https://github.com/spiral-project/ihatemoney/archive/${VERSION}.tar.gz" + + # retrieve and extract Roundcube tarball + tarball="/tmp/ihatemoney.tar.bz2" + rm -f "$tarball" + + wget -q -O "$tarball" "$SOURCE_URL" \ + || ynh_die "Unable to download tarball" + echo "$SHA256 $tarball" | sha256sum -c >/dev/null \ + || ynh_die "Invalid checksum of downloaded tarball" + test -d $DESTDIR || sudo mkdir $DESTDIR + sudo tar xaf "${tarball}" -C "$DESTDIR" --strip-components 1\ + || ynh_die "Unable to extract tarball" + + rm -f "$tarball" +} + + +fix_permissions() { + local SRC_DIR=$1 + + sudo find $SRC_DIR -type f | while read LINE; do sudo chmod 640 "$LINE" ; done + sudo find $SRC_DIR -type d | while read LINE; do sudo chmod 755 "$LINE" ; done + sudo chown -R ihatemoney:ihatemoney $SRC_DIR + sudo chown -R www-data:www-data ${SRC_DIR}/budget/static +} diff --git a/scripts/install b/scripts/install index e010b11..9f82657 100755 --- a/scripts/install +++ b/scripts/install @@ -4,6 +4,9 @@ set -eu # Source YunoHost helpers source /usr/share/yunohost/helpers +# Source local utils +source _common.sh + # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH @@ -56,19 +59,18 @@ ynh_app_setting_set $app is_public "$is_public" # Install debian packages dependencies sudo apt-get install -y -qq python-dev python-virtualenv supervisor libmysqlclient-dev # Create the dedicated user -sudo useradd ihatemoney -d /opt/yunohost/ihatemoney/ +sudo useradd ihatemoney -d /opt/yunohost/ihatemoney/ --create-home + +# Install source +fetch_and_extract /opt/yunohost/ihatemoney/src/ ihatemoney # Prepare venv sudo virtualenv /opt/yunohost/ihatemoney/venv -sudo /opt/yunohost/ihatemoney/venv/bin/pip install -r ../sources/budget/requirements.txt +sudo /opt/yunohost/ihatemoney/venv/bin/pip install -r /opt/yunohost/ihatemoney/src/requirements.txt sudo /opt/yunohost/ihatemoney/venv/bin/pip install gunicorn>=19.3.0 MySQL-python -# 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 -sudo find /opt/yunohost/ihatemoney/src/ -type d | while read LINE; do sudo chmod 755 "$LINE" ; done -sudo chown -R ihatemoney:ihatemoney /opt/yunohost/ihatemoney/src -sudo chown -R www-data:www-data /opt/yunohost/ihatemoney/src/budget/static +# Fix permissions +fix_permissions /opt/yunohost/ihatemoney/src # Create various dirs sudo install -o ihatemoney -g ihatemoney -m 755 \ diff --git a/scripts/upgrade b/scripts/upgrade index d51874f..73f98d6 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -3,14 +3,22 @@ set -eu app=$YNH_APP_INSTANCE_NAME +# The main logic is to +# - install in a src-new folder +# - upgrade dependencies +# - if everything OK, rename src-new to src + # Installation paths INSTALL_DIR=/opt/yunohost/ihatemoney PIP=${INSTALL_DIR}/venv/bin/pip -REQUIREMENTS=${INSTALL_DIR}/src/budget/requirements.txt +NEW_REQUIREMENTS=${INSTALL_DIR}/src-new/requirements.txt # Source YunoHost helpers . /usr/share/yunohost/helpers +# Source local utils +source _common.sh + # Optionaly upgrade arg to typed boolean form is_public=$(ynh_app_setting_get "$app" is_public) @@ -25,17 +33,19 @@ fi ynh_app_setting_set "$app" is_public "$is_public" # Upgrade code -sudo rsync -a --delete-after ../sources/ ${INSTALL_DIR}/src/ -sudo find ${INSTALL_DIR}/src/ -type f | while read LINE; do sudo chmod 640 "$LINE" ; done -sudo find ${INSTALL_DIR}/src/ -type d | while read LINE; do sudo chmod 755 "$LINE" ; done -sudo chown -R ihatemoney:ihatemoney /opt/yunohost/ihatemoney/src -sudo chown -R www-data:www-data /opt/yunohost/ihatemoney/src/budget/static +fetch_and_extract ${INSTALL_DIR}/src-new/ ihatemoney -# Re-create settings symlink -sudo ln -s /etc/ihatemoney/settings.py /opt/yunohost/ihatemoney/src/budget/settings.py +fix_permissions ${INSTALL_DIR}/src-new/ # Upgrade dependencies -sudo ${PIP} install -r ${REQUIREMENTS} +sudo ${PIP} install -r ${NEW_REQUIREMENTS} + +# Everything went ok ? Let's keep this code. +sudo rm -rf ${INSTALL_DIR}/src +sudo mv ${INSTALL_DIR}/src-new ${INSTALL_DIR}/src + +# Re-create settings symlink +sudo ln -s /etc/ihatemoney/settings.py ${INSTALL_DIR}/src/budget/settings.py # Settings are not very likely to change, and that script may be # adapted to handle it in case.