From cfef8b83da8062574bd8a608a3a0c4edc8f91098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 16 Jul 2016 14:07:49 +0200 Subject: [PATCH] [enh] Add the upgrade script and update README.md --- README.md | 7 +---- scripts/upgrade | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 scripts/upgrade diff --git a/README.md b/README.md index e15e9d0..a706108 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,7 @@ extracts content so that you can read it when you have time. ## TODO * Improve the LDAP integration, see [#1](https://github.com/YunoHost-Apps/wallabag2_ynh/issues/1) - * Add a `post_user_create` hook to create new YunoHost users in Wallabag - - or consider to do that dynamically - * Write the `upgrade` / `backup` / `restore` scripts - * Consider using composer to fetch dependencies and retrieve Wallabag sources - from the git repository - as suggested in the - [official documentation](http://doc.wallabag.org/en/master/user/installation.html#on-a-dedicated-web-server-recommended-way) + * Write the `backup` / `restore` scripts ## Upgrade from v1 diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..7b65e01 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,70 @@ +#!/bin/bash + +# Exit on command errors and treat unset variables as an error +set -eu + +# Load common variables and helpers +source ./_common.sh + +# Set app specific variables +app=$YNH_APP_INSTANCE_NAME +dbname=$app +dbuser=$app + +# Retrieve arguments +domain=$(ynh_app_setting_get "$app" domain) +path=$(ynh_app_setting_get "$app" path) +path=${path%/} +dbpass=$(ynh_app_setting_get "$app" mysqlpwd) +deskey=$(ynh_app_setting_get "$app" deskey) + +# Check destination directory +DESTDIR="/var/www/$app" +[[ ! -d $DESTDIR ]] && ynh_die \ +"The destination directory '$DESTDIR' does not exist.\ + The app is not correctly installed, you should remove it first." + +# Install dependencies +ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \ + || ynh_die "Unable to install dependencies" + +# Create tmp directory and fetch app inside +TMPDIR=$(ynh_mkdir_tmp) +extract_wallabag "$TMPDIR" + +# Copy and set Wallabag dist configuration +wb_conf="${TMPDIR}/app/config/parameters.yml" +cp ../conf/parameters.yml "$wb_conf" +sed -i "s@{DBNAME}@${dbname}@g" "$wb_conf" +sed -i "s@{DBUSER}@${dbuser}@g" "$wb_conf" +sed -i "s@{DBPASS}@${dbpass}@g" "$wb_conf" +sed -i "s@{DESKEY}@${deskey}@g" "$wb_conf" + +# Replace files and set permissions +sudo rm -rf "$DESTDIR" +sudo mv "$TMPDIR" "$DESTDIR" +sudo chown -R www-data: "$DESTDIR" + +# Clear Wallabag cache +exec_console www-data "$DESTDIR" cache:clear + +# Copy and set nginx configuration +nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" +sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf +sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf +sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf +sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf "$nginx_conf" + +# Copy and set php-fpm configuration +phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf +sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf +sudo cp ../conf/php-fpm.conf "$phpfpm_conf" + +# Set SSOwat rules +ynh_app_setting_set "$app" unprotected_uris "/" + +# Reload services +sudo service php5-fpm restart +sudo service nginx reload