From 96bce7d455b470bd90f65bb934d219cbbb371a98 Mon Sep 17 00:00:00 2001 From: src386 Date: Mon, 11 Jul 2016 18:41:22 +0200 Subject: [PATCH] YunoHost 2.2 compatibility and backport 2.4 helpers --- CHANGELOG | 10 ++++-- README.md | 2 +- manifest.json | 11 +++---- scripts/_common.sh | 2 +- scripts/_helpers.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 12 +++++-- scripts/install | 27 ++++++++++------ scripts/remove | 12 +++++-- scripts/restore | 12 +++++-- scripts/upgrade | 32 ++++++++++++------- 10 files changed, 159 insertions(+), 39 deletions(-) create mode 100644 scripts/_helpers.sh diff --git a/CHANGELOG b/CHANGELOG index 1803166..996dcc6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,13 @@ **Changelog** -1.8.1 2016-05-30 -- Update to movim 0.9 git2016-05-30 +2.0 2016? +- Major code improvement thanks to @jeromelebleu, #28 : + - Download and update source code using git (fixed HEAD COMMIT though) + - Make use of new YunoHost helpers coming with the 2.4 version + - Add backup and restore scripts + - Redirect to the SSO on logging out +- YunoHost 2.4 helpers backport if 2.2 detected (_helpers.sh) +- Update to movim 0.9 git 2016-07-10 1.8 2016-04-15 - Update to movim 0.9 git2016-04-15 diff --git a/README.md b/README.md index ba64943..045e808 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Movim is a decentralized social network, written in PHP and HTML5 and based on t It is recommended to use a "valid" certificate to use Movim, auto-signed is sometimes problematic. You might want to take a look a StartSSL or Let's Encrypt. -Provided Movim version : 0.9 git2016-05-30 +Provided Movim version : 0.9 git2016-07-10 Please read CHANGELOG. diff --git a/manifest.json b/manifest.json index 47fb235..b72daa1 100644 --- a/manifest.json +++ b/manifest.json @@ -17,9 +17,6 @@ "mysql", "metronome" ], - "requirements": { - "yunohost": ">= 2.4.0" - }, "multi_instance": false, "arguments": { "install" : [ @@ -71,12 +68,12 @@ }, { "name": "ssoenabled", - "type": "boolean", "ask": { - "en": "Enable SSO support (autologin)?", - "fr": "Activer le support du SSO (connexion auto) ?" + "en": "Enable SSO support (autologin) ?", + "fr": "Activer le support SSO (connexin auto) ?" }, - "default": true + "choices": ["Yes", "No"], + "default": "Yes" }, { "name": "port", diff --git a/scripts/_common.sh b/scripts/_common.sh index cd6c320..0ccb9d5 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,7 +6,7 @@ GIT_REPO="https://github.com/movim/movim" # Commit to checkout -HEAD_COMMIT="512523576b03c2c8952305e70681ed31172b9fd2" +HEAD_COMMIT="8f56192582e83f4b1dbaa00aab8feb55031598e4" # Source code destination directory DESTDIR="/var/www/movim" diff --git a/scripts/_helpers.sh b/scripts/_helpers.sh new file mode 100644 index 0000000..b8055d9 --- /dev/null +++ b/scripts/_helpers.sh @@ -0,0 +1,78 @@ +# +# Yunohost helpers +# + +ynh_die() { + echo "$1" 1>&2 + exit "${2:-1}" +} + +ynh_user_exists() { + sudo yunohost user info $admin +} + +ynh_system_user_exists() { + getent passwd "$1" &>/dev/null +} + +ynh_app_setting_get() { + sudo yunohost app setting "$1" "$2" +} + +ynh_app_setting_set() { + sudo yunohost app setting "$1" "$2" -v "$3" +} + +ynh_app_setting_delete() { + sudo yunohost app setting -d "$1" "$2" +} + +ynh_string_random() { + dd if=/dev/urandom bs=1 count=200 2> /dev/null \ + | tr -c -d '[A-Za-z0-9]' \ + | sed -n 's/\(.\{'"${1:-24}"'\}\).*/\1/p' +} + +MYSQL_ROOT_PWD_FILE=/etc/yunohost/mysql + +ynh_mysql_create_db() { + db=$1 + + sql="CREATE DATABASE ${db};" + + # grant all privilegies to user + if [[ $# -gt 1 ]]; then + sql+=" GRANT ALL PRIVILEGES ON ${db}.* TO '${2}'@'localhost'" + [[ -n ${3:-} ]] && sql+=" IDENTIFIED BY '${3}'" + sql+=" WITH GRANT OPTION;" + fi + + ynh_mysql_execute_as_root "$sql" +} + +ynh_mysql_drop_db() { + ynh_mysql_execute_as_root "DROP DATABASE ${1};" +} + +ynh_mysql_drop_user() { + ynh_mysql_execute_as_root "DROP USER '${1}'@'localhost';" +} + +ynh_mysql_execute_as_root() { + ynh_mysql_connect_as "root" "$(sudo cat $MYSQL_ROOT_PWD_FILE)" \ + "${2:-}" <<< "$1" +} + +ynh_mysql_connect_as() { + mysql -u "$1" --password="$2" -B "${3:-}" +} + + +ynh_package_install() { + ynh_apt -o Dpkg::Options::=--force-confdef \ + -o Dpkg::Options::=--force-confold install $@ +} + +ynh_apt() { + DEBIAN_FRONTEND=noninteractive sudo apt-get -y -qq $@ +} diff --git a/scripts/backup b/scripts/backup index 58a2b2e..04502f6 100644 --- a/scripts/backup +++ b/scripts/backup @@ -7,8 +7,16 @@ app="movim" db_user=$app db_name=$app -# Source YunoHost helpers -source /usr/share/yunohost/helpers +# Source local helpers +source ./_common.sh + +# Source YunoHost helpers if exists. +# If not, source backported helpers from file. +if [ -d "/usr/share/yunohost/helpers" ]; then + source /usr/share/yunohost/helpers +else + source ./_helpers.sh +fi # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) diff --git a/scripts/install b/scripts/install index d67cb1b..ffd0933 100644 --- a/scripts/install +++ b/scripts/install @@ -15,10 +15,17 @@ ssoenabled=$6 port=$7 timezone=`cat /etc/timezone` -# Source YunoHost and local helpers -source /usr/share/yunohost/helpers +# Source local helpers source ./_common.sh +# Source YunoHost helpers if exists. +# If not, source backported helpers from file. +if [ -d "/usr/share/yunohost/helpers" ]; then + source /usr/share/yunohost/helpers +else + source ./_helpers.sh +fi + # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ || exit 1 @@ -63,8 +70,8 @@ ynh_package_install php5-gd php5-curl php5-imagick php5-cli # Download Movim source code tmp_path=/tmp/movim-git sudo rm -rf "$tmp_path" -(git clone --quiet "$GIT_REPO" "$tmp_path" \ - && cd "$tmp_path" && git checkout --quiet "$HEAD_COMMIT") \ +(git clone "$GIT_REPO" "$tmp_path" \ + && cd "$tmp_path" && git checkout "$HEAD_COMMIT") \ || ynh_die "Unable to download Movim source code." # Set database configuration @@ -89,9 +96,9 @@ sudo chmod 400 "${DESTDIR}/config/db.inc.php" # Install PHP dependencies using composer (curl -sS https://getcomposer.org/installer \ - | exec_cmd php -- --quiet --install-dir="$DESTDIR" \ + | exec_cmd php -- --install-dir="$DESTDIR" \ && exec_cmd php composer.phar config --global discard-changes true \ - && exec_cmd php composer.phar install --quiet --no-interaction) \ + && exec_cmd php composer.phar install --no-interaction) \ || ynh_die "Unable to install Movim dependencies." # Set Movim database and configuration @@ -106,9 +113,9 @@ sudo sed -i "s@YHDIR@${DESTDIR}@g" ../conf/movim.{service,init} sudo sed -i "s@YHPORT@${port}@g" ../conf/movim.{service,init} if [ -d /run/systemd/system ]; then sudo cp ../conf/movim.service /etc/systemd/system/ - sudo systemctl --quiet daemon-reload - sudo systemctl --quiet enable movim.service - sudo systemctl --quiet start movim.service + sudo systemctl daemon-reload + sudo systemctl enable movim.service + sudo systemctl start movim.service else sudo cp ../conf/movim.init /etc/init.d/movim sudo chmod 755 /etc/init.d/movim @@ -128,7 +135,7 @@ sed -i "s@//ws/@/ws/@g" ../conf/nginx.conf # Avoid duplicate / sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/movim.conf # SSOwat configuration -if [[ "$ssoenabled" = "0" ]]; then +if [[ "$ssoenabled" = "No" ]]; then ynh_app_setting_set "$app" skipped_uris "/" exec_cmd php mud.php config --xmppwhitelist="$domain" else diff --git a/scripts/remove b/scripts/remove index e23178b..a44eba1 100644 --- a/scripts/remove +++ b/scripts/remove @@ -2,8 +2,16 @@ app="movim" -# Source YunoHost helpers -source /usr/share/yunohost/helpers +# Source local helpers +source ./_common.sh + +# Source YunoHost helpers if exists. +# If not, source backported helpers from file. +if [ -d "/usr/share/yunohost/helpers" ]; then + source /usr/share/yunohost/helpers +else + source ./_helpers.sh +fi # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) diff --git a/scripts/restore b/scripts/restore index 7e39d6d..b36261b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -7,8 +7,16 @@ app="movim" db_name=$app db_user=$app -# Source YunoHost helpers -source /usr/share/yunohost/helpers +# Source local helpers +source ./_common.sh + +# Source YunoHost helpers if exists. +# If not, source backported helpers from file. +if [ -d "/usr/share/yunohost/helpers" ]; then + source /usr/share/yunohost/helpers +else + source ./_helpers.sh +fi # Retrieve old app settings domain=$(ynh_app_setting_get "$app" domain) diff --git a/scripts/upgrade b/scripts/upgrade index b78f169..1826d96 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -5,10 +5,17 @@ set -eu app="movim" -# Source YunoHost and local helpers -source /usr/share/yunohost/helpers +# Source local helpers source ./_common.sh +# Source YunoHost helpers if exists. +# If not, source backported helpers from file. +if [ -d "/usr/share/yunohost/helpers" ]; then + source /usr/share/yunohost/helpers +else + source ./_helpers.sh +fi + # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) @@ -28,8 +35,8 @@ if [ ! -d "${DESTDIR}/.git" ]; then sudo rm -rf "$tmp_path" # Download Movim source code - (git clone --quiet "$GIT_REPO" "$tmp_path" \ - && cd "$tmp_path" && git checkout --quiet "$HEAD_COMMIT") \ + (git clone "$GIT_REPO" "$tmp_path" \ + && cd "$tmp_path" && git checkout "$HEAD_COMMIT") \ || ynh_die "Unable to download Movim source code." sudo cp "${DESTDIR}/config/db.inc.php" "${tmp_path}/config/db.inc.php" @@ -40,12 +47,12 @@ if [ ! -d "${DESTDIR}/.git" ]; then # Install composer for PHP dependencies curl -sS https://getcomposer.org/installer \ - | exec_cmd php -- --quiet --install-dir="$DESTDIR" + | exec_cmd php -- --install-dir="$DESTDIR" fi # Update Movim source code -(exec_cmd git fetch --quiet origin \ - && exec_cmd git reset --quiet --hard "$HEAD_COMMIT") \ +(exec_cmd git fetch origin \ + && exec_cmd git reset --hard "$HEAD_COMMIT") \ || ynh_die "Unable to download Movim source code." ## FIXME: consider installation in a subpath exec_cmd sed -i "s@'/ws/'@'${path%/}/ws/'@g" \ @@ -61,7 +68,7 @@ sudo chmod 400 "${DESTDIR}/config/db.inc.php" # Update PHP dependencies using composer (exec_cmd php composer.phar config --global discard-changes true \ - && exec_cmd php composer.phar install --quiet --no-interaction) \ + && exec_cmd php composer.phar install --no-interaction) \ || ynh_die "Unable to update Movim dependencies." # Upgrade Movim database as needed @@ -75,16 +82,17 @@ sudo yunohost app clearaccess movim # Replace old public_site variable (if exists) by ssoenabled if [ ! -z "$public_site" ]; then [[ $public_site = "Yes" ]] \ - && ssoenabled=0 \ - || ssoenabled=1 + && ssoenabled="No" \ + || ssoenabled="Yes" ynh_app_setting_delete "$app" public_site ynh_app_setting_set "$app" ssoenabled "$ssoenabled" fi # SSOwat configuration -if [[ "$ssoenabled" =~ ^0|No$ ]]; then +if [[ "$ssoenabled" = "No" ]]; then ynh_app_setting_set "$app" skipped_uris "/" exec_cmd php mud.php config --xmppwhitelist=$domain + sudo yunohost app ssowatconf else ynh_app_setting_set "$app" unprotected_uris "/" apply_sso_patch @@ -97,7 +105,7 @@ sudo sed -i "s@YHPORT@${port}@g" ../conf/movim.{service,init} if [ -d /run/systemd/system ]; then sudo rm -f /lib/systemd/system/movim.service sudo cp ../conf/movim.service /etc/systemd/system/ - sudo systemctl --quiet daemon-reload + sudo systemctl daemon-reload else sudo /etc/init.d/movim stop sudo cp ../conf/movim.init /etc/init.d/movim