From 3143d6082859f1041681df5c6e4fe499cd3e3243 Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 19 Mar 2018 03:56:00 +0100 Subject: [PATCH] [enh] Level 7 --- README.md | 63 +++++++++- YEP.md | 117 +++++++++++++++++++ check_process | 14 ++- conf/app.src | 5 +- conf/config.js.j2 | 0 conf/custom.css.j2 | 0 conf/nginx.conf | 11 -- conf/nginx.conf.j2 | 17 +++ manifest.json | 1 + scripts/_common.sh | 281 +++++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 9 +- scripts/install | 95 +++++++-------- scripts/remove | 12 +- scripts/restore | 48 ++++---- scripts/upgrade | 80 ++++++------- 15 files changed, 608 insertions(+), 145 deletions(-) create mode 100644 YEP.md create mode 100644 conf/config.js.j2 create mode 100644 conf/custom.css.j2 delete mode 100644 conf/nginx.conf create mode 100644 conf/nginx.conf.j2 create mode 100644 scripts/_common.sh diff --git a/README.md b/README.md index 0142fb9..8c80a5b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,63 @@ # SVG Edit app for YunoHost -- [Yunohost project](https://yunohost.org) -- [SVG Edit app website](https://github.com/SVG-Edit/svgedit) +[![Integration level](https://dash.yunohost.org/integration/svgedit.svg)](https://ci-apps.yunohost.org/jenkins/job/svgedit%20%28Community%29/lastBuild/consoleFull) +[![Install SVG Edit with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=svgedit) -![alt text](https://svg-edit.github.io/svgedit/images/logo48x48.svg "svg-edit logo of a pencil") SVG-edit -=== +> *This package allow you to install SVG Edit quickly and simply on a YunoHost server. +If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* + +## Overview SVG-edit is a fast, web-based, javascript-driven SVG drawing editor that works in any modern browser. + +**Shipped version:** 2.8.1 + +**Categories:** Productivity, Drawing + +## Screenshots +![alt text](https://svg-edit.github.io/svgedit/images/logo48x48.svg "svg-edit logo of a pencil") SVG-edit + + +## Configuration + +## Documentation + +* YunoHost documentation: There no other documentations, feel free to contribute. + +## YunoHost specific features + +#### Multi-users support + +Not supported. + +#### Supported architectures + +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/svgedit%20(Community)/) +* ARMv8-A - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/leed%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/svgedit%20(Community)%20(%7EARM%7E)/) + +## Limitations + +* There is no account management in SVG Edit, but the SSO can protect the access to the app to disallow user without yunohost account. + +## Additionnal informations + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/svgedit_ynh/issues + * Website: https://github.com/SVG-Edit/svgedit + * YunoHost website: https://yunohost.org/ + +--- + +Developers infos +---------------- + +**Package by:** Luc Didry + +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/svgedit_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/svgedit_ynh/tree/testing --verbose +or +sudo yunohost app upgrade leed -u https://github.com/YunoHost-Apps/svgedit_ynh/tree/testing --verbose +``` diff --git a/YEP.md b/YEP.md new file mode 100644 index 0000000..0fb8fbf --- /dev/null +++ b/YEP.md @@ -0,0 +1,117 @@ +#### [Level 0](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-0) +[YEP 1.1 - Nommer son app et son dépot](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) +`Validated` +[YEP 1.2 - Inscrire l'app sur un "répertoire" connu](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-12) +`Validated` + +#### [Level 1](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-1) +[YEP 2.2 - Utiliser bash pour les scripts principaux](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-22) +`Validated` +[YEP 2.5 - Copier correctement des fichiers](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-25) +`Don't know` +[YEP 2.7 - Donner des permissions suffisantes aux instructions bash](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-27) +`Validated` +[YEP 2.15 - Suivre les instructions d'installation de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-215) +`Validated` + +#### [Level 2](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-2) +[YEP 1.5 - Mettre à jour régulièrement le statut de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) +`Validated` +[YEP 2.18.2 - Gérer l'installation à la racine d’un nom de domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2182) +`Validated` - *Automatically verified.* +[YEP 2.18.3 - Gérer l'installation sur un sous-domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2183) +`Validated` - *Automatically verified.* +[YEP 2.18.4 - Gérer l'installation sur un chemin /path](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2184) +`Validated` - *Automatically verified.* +[YEP 4.6 - Gère le multi-instance](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) +`Validated` - *Automatically verified.* + +#### [Level 3](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-3) +[YEP 2.3 - Sauvegarder les réponses lors de l'installation](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-23) +`Validated` + +#### [Level 4](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-4) +[YEP 4.1 - Lier au ldap](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-41) +`Not applicable` +[YEP 4.2 - Lier l'authentification au sso](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-42) +`Validated` + +#### [Level 5](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-5) +[YEP 1.3 - Indiquer la licence associée au paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13) +`Validated` +[YEP 2.1 - Respecter le format du manifeste](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-21) +`Validated` - *Automatically verified.* +[YEP 2.12 - Utiliser les commandes pratiques (helpers)](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-212) +`Validated` +[YEP 2.18.1 - Lancer le script d'installation d'une webapp correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2181) +`Validated` + +#### [Level 6](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-6) +[YEP 1.4 - Informer sur l'intention de maintenir un paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-14) +`Not yet validated` +[YEP 1.6 - Se tenir informé sur l'évolution du packaging d'apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-16) +`Validated` +[YEP 1.7 - Ajouter l'app à l'organisation YunoHost-Apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-17) +`Validated` - *Automatically verified.* +[YEP 1.8 - Publier des demandes de test](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-18) +`Not yet validated` +[YEP 1.9 - Documenter l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-19) +`Validated` +[YEP 1.10 - Garder un historique de version propre](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-110) +`Validated` +[YEP 2.9 - Enlever toutes traces de l'app lors de la suppression](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-29) +`Validated` +[YEP 3.3 - Faciliter le contrôle de l'intégrité des sources](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-33) +`Validated` +[YEP 3.5 - Suivre les recommendations de la documentation de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-35) +`Validated` +[YEP 3.6 - Mettre à jour les versions contenant des CVE](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-36) +`Validated` +[YEP 4.3 - Fournir un script de sauvegarde YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-43) +`Validated` - *Automatically verified.* +[YEP 4.4 - Fournir un script de restauration YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-44) +`Validated` - *Automatically verified.* + +#### [Level 7](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-7) +[YEP 2.6 - Annuler l'action si les valeurs d'entrées sont incorrectes](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-26) +`Validated` +[YEP 3.2 - Ouvrir un port correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-32) +`Not applicable` + +#### [Level 8](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-8) +[YEP 2.4 - Détecter et gérer les erreurs](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-24) +`Validated` +[YEP 2.8 - Modifier correctement une configuration système](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-28) +`Validated` +[YEP 2.16 - Vérifier la disponibilité des dépendances sur ARM, x86 et x64](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-216) +`Not yet validated` - *Automatically verified.* +[YEP 2.18.5 - Gérer la tuile YunoHost pour faciliter la navigation entre les applications](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2185) +`Validated` +[YEP 3.4 - Isoler l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-34) +`Not validated` +[YEP 4.5 - Utiliser les hooks](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-45) +`Not applicable` + +#### [Level 9](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-9) +[YEP 2.10 - Configurer les logs de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-210) +`Not applicable` +[YEP 2.11 - Utiliser une variable plutôt que l'app id directement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-211) +`Validated` +[YEP 2.13 - Traduire le paquet en anglais](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-213) +`Validated` +[YEP 2.14 - Remplir correctement un fichier de conf](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-214) +`Validated` +[YEP 2.17 - Prendre en compte la version d'origine lors des mises à jour](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-217) +`Validated` +[YEP 4.2.1 - Déconnexion](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-421) +`Not applicable` + +#### Other YEP +[YEP 3.1 - Ne pas demander ou stocker de mot de passe LDAP](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-31) +`Validated` +[YEP 4.7 - Ajouter un module à la CLI](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-47) +`Not applicable` +[YEP 4.8 - Ajouter un module à l'admin web](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-48) +`Not applicable` + +State of each YEP can be one of these: `Validated`, `Partially validated`, `Not yet validated`, `Not applicable`, `Don't know`. diff --git a/check_process b/check_process index 121f35c..e147ab4 100644 --- a/check_process +++ b/check_process @@ -12,18 +12,30 @@ setup_private=1 setup_public=1 upgrade=1 + upgrade=1 from_commit=6f3a05b03d60142ad19ee8815f7b5d68adc888a4 backup_restore=1 multi_instance=1 + wrong_user=1 + wrong_path=1 incorrect_path=1 + corrupt_source=1 + fail_download_source=1 port_already_use=0 + final_path_already_use=1 + change_url=0 ;;; Levels Level 1=auto Level 2=auto Level 3=auto - Level 4=0 +# SVG edit as no account management, but ssowat is configured (is_public feature) + Level 4=1 Level 5=auto Level 6=auto Level 7=auto Level 8=0 Level 9=0 Level 10=0 +;;; Upgrade options + ; commit=6f3a05b03d60142ad19ee8815f7b5d68adc888a4 + name=2.8.1 6f3a05b03d60142ad19ee8815f7b5d68adc888a4 + manifest_arg=domain=DOMAIN&path=PATH&is_public=1& diff --git a/conf/app.src b/conf/app.src index 4c30667..f5a3c9a 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,2 +1,5 @@ SOURCE_URL=https://github.com/SVG-Edit/svgedit/releases/download/svg-edit-2.8.1/svg-edit-2.8.1.zip -SOURCE_SUM=982687a16035944494c6be4f7c5e6972 +SOURCE_SUM=416799c4fcb3dcbe7fa5c4ac6409a2891afc4fa759b654bcb5e6df55e259bfe1 +SOURCE_IN_SUBDIR=true +SOURCE_FORMAT=zip +SOURCE_FILENAME=svg-edit-2-8-1.tar.gz diff --git a/conf/config.js.j2 b/conf/config.js.j2 new file mode 100644 index 0000000..e69de29 diff --git a/conf/custom.css.j2 b/conf/custom.css.j2 new file mode 100644 index 0000000..e69de29 diff --git a/conf/nginx.conf b/conf/nginx.conf deleted file mode 100644 index 5810b50..0000000 --- a/conf/nginx.conf +++ /dev/null @@ -1,11 +0,0 @@ -location YNH_WWW_PATH { - - # Path to source - alias YNH_WWW_ALIAS ; - - # Example PHP configuration (remove if not used) - index svg-editor.html; - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; -} diff --git a/conf/nginx.conf.j2 b/conf/nginx.conf.j2 new file mode 100644 index 0000000..b655208 --- /dev/null +++ b/conf/nginx.conf.j2 @@ -0,0 +1,17 @@ +{% if path_url != "/" %} +rewrite ^{{ path_url }}$ {{ path_url }}/ permanent; +{% else %} +{% set path_url = "" %} +{% endif %} +location {{ path_url }}/ { + alias {{ final_path }}/; + + index svg-editor.html; + + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/manifest.json b/manifest.json index 019858c..905d78b 100644 --- a/manifest.json +++ b/manifest.json @@ -7,6 +7,7 @@ "fr": "SVG-edit est un outil de manipulation de SVG en ligne, rapide, et écrit en javascript qui fonctionne avec tout navigateur moderne." }, "url": "https://github.com/SVG-Edit/svgedit", + "version": "2.8.1-1", "license": "MIT", "maintainer": { "name": "Luc Didry", diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..9ee6fc3 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,281 @@ +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= +# App package root directory should be the parent folder +PKG_DIR=$(cd ../; pwd) + +pkg_dependencies="wget" + +#================================================= +# COMMON HELPERS +#================================================= +ynh_set_default_perm () { + local DIRECTORY=$1 + local user=$YNH_APP_INSTANCE_NAME + id -u $user 2>/dev/null || user=root + # Set permissions + chown -R $user:www-data $DIRECTORY + chmod -R 440 $DIRECTORY + find $DIRECTORY -type d -print0 | xargs -0 chmod 550 \ + || echo "No file to modify" + +} +ynh_export () { + local ynh_arg="" + for var in $@; + do + ynh_arg=$(echo $var | awk '{print toupper($0)}') + if [ "$var" == "path_url" ]; then + ynh_arg="PATH" + fi + ynh_arg="YNH_APP_ARG_$ynh_arg" + export $var=${!ynh_arg} + done +} +ynh_get_and_export () { + local ynh_arg="" + for var in $@; + do + ynh_arg=$var + if [ "$var" == "path_url" ]; then + ynh_arg="path" + fi + export $var=$(ynh_app_setting_get $app $ynh_arg) + done +} + +# Check the path doesn't exist +# usage: ynh_final_path_available PATH +ynh_final_path_available () { + if [ -e "$final_path" ] + then + ynh_die "This path '$final_path' already contains a folder" + fi +} + +# Save listed var in YunoHost app settings +# usage: ynh_save_args VARNAME1 [VARNAME2 [...]] +ynh_save_args () { + for var in $@; + do + local setting_var="$var" + if [ "$var" == "path_url" ]; then + setting_var="path" + fi + ynh_app_setting_set $app $setting_var ${!var} + done +} +ynh_sso_access () { + ynh_app_setting_set $app unprotected_uris "/" + + if [[ $is_public -eq 0 ]]; then + ynh_app_setting_set $app protected_uris "$1" + fi + yunohost app ssowatconf +} + +ynh_exit_if_up_to_date () { + if [ "${version}" = "${last_version}" ]; then + info "Up-to-date, nothing to do" + ynh_die "Up-to-date, nothing to do" 0 + fi +} + +log() { + echo "${1}" +} + +info() { + log "[INFO] ${1}" +} + +warn() { + log "[WARN] ${1}" +} + +err() { + log "[ERR] ${1}" +} + +to_logs() { + + # When yunohost --verbose or bash -x + if $_ISVERBOSE; then + cat + else + cat > /dev/null + fi +} + +ynh_read_json () { + sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" +} + +ynh_read_manifest () { + if [ -f '../manifest.json' ] ; then + ynh_read_json '../manifest.json' "$1" + else + ynh_read_json '../settings/manifest.json' "$1" + fi +} + + +ynh_configure () { + local TEMPLATE=$1 + local DEST=$2 + type j2 2>/dev/null || sudo pip install j2cli + j2 "${PKG_DIR}/conf/$TEMPLATE.j2" > "${PKG_DIR}/conf/$TEMPLATE" + ynh_backup_if_checksum_is_different "$DEST" + sudo cp "${PKG_DIR}/conf/$TEMPLATE" "$DEST" + ynh_store_file_checksum "$DEST" + sudo chown root: "$DEST" +} + +ynh_add_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_configure nginx.conf "$finalnginxconf" + service nginx reload +} + +# Send an email to inform the administrator +# +# usage: ynh_send_readme_to_admin app_message [recipients] +# | arg: app_message - The message to send to the administrator. +# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root +# example: "root admin@domain" +# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you +# example: "root admin@domain user1 user2" +ynh_send_readme_to_admin() { + local app_message="${1:-...No specific information...}" + local recipients="${2:-root}" + + # Retrieve the email of users + find_mails () { + local list_mails="$1" + local mail + local recipients=" " + # Read each mail in argument + for mail in $list_mails + do + # Keep root or a real email address as it is + if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" + then + recipients="$recipients $mail" + else + # But replace an user name without a domain after by its email + if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) + then + recipients="$recipients $mail" + fi + fi + done + echo "$recipients" + } + recipients=$(find_mails "$recipients") + + local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!" + + local mail_message="This is an automated message from your beloved YunoHost server. +Specific information for the application $app. +$app_message +--- +Automatic diagnosis data from YunoHost +$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" + + # Send the email to the recipients + echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" +} + +# Exit without error if the package is up to date +# +# This helper should be used to avoid an upgrade of a package +# when it's not needed. +# +# To force an upgrade, even if the package is up to date, +# you have to set the variable YNH_FORCE_UPGRADE before. +# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp +# +# usage: ynh_abort_if_up_to_date +ynh_abort_if_up_to_date () { + local force_upgrade=${YNH_FORCE_UPGRADE:-0} + local package_check=${PACKAGE_CHECK_EXEC:-0} + + local version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + local last_version=$(ynh_read_manifest "version" || echo 1.0) + if [ "$version" = "$last_version" ] + then + if [ "$force_upgrade" != "0" ] + then + echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 + unset YNH_FORCE_UPGRADE + elif [ "$package_check" != "0" ] + then + echo "Upgrade forced for package check." >&2 + else + ynh_die "Up-to-date, nothing to do" 0 + fi + fi +} + +# Remove any logs for all the following commands. +# +# usage: ynh_print_OFF +# WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging. +ynh_print_OFF () { + set +x +} + +# Restore the logging after ynh_print_OFF +# +# usage: ynh_print_ON +ynh_print_ON () { + set -x + # Print an echo only for the log, to be able to know that ynh_print_ON has been called. + echo ynh_print_ON > /dev/null +} +ynh_version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } + +# In upgrade script allow to test if the app is less than or equal a specific version +# +# usage: ynh_version_le "0.5" +ynh_version_le() { + local version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + ynh_version_gt "$1" "${version}" +} + +ynh_debian_release () { + lsb_release --codename --short +} + +is_stretch () { + if [ "$(ynh_debian_release)" == "stretch" ] + then + return 0 + else + return 1 + fi +} + +is_jessie () { + if [ "$(ynh_debian_release)" == "jessie" ] + then + return 0 + else + return 1 + fi +} + +# Reload (or other actions) a service and print a log in case of failure. +# +# usage: ynh_system_reload service_name [action] +# | arg: service_name - Name of the service to reload +# | arg: action - Action to perform with systemctl. Default: reload +ynh_system_reload () { + local service_name=$1 + local action=${2:-reload} + + # Reload, restart or start and print the log if the service fail to start or reload + systemctl $action $service_name || ( journalctl --lines=20 -u $service_name >&2 && false) +} diff --git a/scripts/backup b/scripts/backup index f944306..8c7d709 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,18 +1,17 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu - # See comments in install script app=$YNH_APP_INSTANCE_NAME # Source YunoHost helpers source /usr/share/yunohost/helpers +ynh_abort_if_errors + # Backup sources & data # Note: the last argument is where to save this path, see the restore script. -ynh_backup "/var/www/${app}" "sources" +ynh_backup "/var/www/${app}" # Copy NGINX configuration domain=$(ynh_app_setting_get "$app" domain) -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" +ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" diff --git a/scripts/install b/scripts/install index 6f1122f..104a443 100755 --- a/scripts/install +++ b/scripts/install @@ -1,70 +1,55 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu - -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... -app=$YNH_APP_INSTANCE_NAME - -# Retrieve arguments -domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH -is_public=$YNH_APP_ARG_IS_PUBLIC - # Source YunoHost helpers source /usr/share/yunohost/helpers +source _common.sh + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +export app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +ynh_export domain path_url is_public +export final_path=/var/www/$app + +# Check if the app can be installed with this args +ynh_final_path_available + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url # Save app settings -ynh_app_setting_set "$app" is_public "$is_public" - -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_save_args is_public final_path path_url # Check needed packages -if ! ynh_package_is_installed "wget" ; then - apt-get install -y wget -fi -if ! ynh_package_is_installed "unzip" ; then - apt-get install -y unzip -fi +ynh_install_app_dependencies $pkg_dependencies # Copy source files -src_path=/var/www/$app -sudo mkdir -p $src_path -mkdir ../sources/ -cd ../sources/ -wget -q https://github.com/SVG-Edit/svgedit/releases/download/svg-edit-2.8.1/svg-edit-2.8.1.zip -unzip svg-edit-2.8.1.zip -cd - -sudo cp -a ../sources/svg-edit-2.8.1/. $src_path -rm -rf ../sources/svg-edit-2.8.1/ ../sources/svg-edit-2.8.1.zip -touch $src_path/config.js $src_path/custom.css +ynh_setup_source "$final_path" + +# Custom instructions +ynh_configure config.js "$final_path/config.js" +ynh_configure custom.css "$final_path/custom.css" # Set permissions to app files -# you may need to make some file and/or directory writeable by www-data (nginx user) -sudo chown -R root: $src_path - -# Modify Nginx configuration file and copy it to Nginx conf directory -nginx_conf=../conf/nginx.conf -sed -i "s@YNH_WWW_PATH@$path_url@g" $nginx_conf -sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf -sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf +ynh_set_default_perm "$final_path" # If app is public, add url to SSOWat conf as skipped_uris -if [[ $is_public -eq 1 ]]; then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" -fi +ynh_sso_access "/" -# Reload services -sudo service nginx reload +# Modify Nginx configuration file and copy it to Nginx conf directory +ynh_add_nginx_config + +# Send a readme to the admin +ynh_print_OFF +message="You can now draw this address: https://${domain}${path_url}/ +If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/svgedit_ynh" + +ynh_send_readme_to_admin "$message" +ynh_print_ON diff --git a/scripts/remove b/scripts/remove index 9a5dc51..d2783bd 100755 --- a/scripts/remove +++ b/scripts/remove @@ -5,15 +5,17 @@ app=$YNH_APP_INSTANCE_NAME # Source YunoHost helpers source /usr/share/yunohost/helpers +source _common.sh # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) +final_path=$(ynh_app_setting_get "$app" final_path) + +# Remove dependencies +ynh_remove_app_dependencies # Remove sources -sudo rm -rf /var/www/$app +ynh_secure_remove $final_path # Remove nginx configuration file -sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf - -# Reload nginx service -sudo service nginx reload +ynh_remove_nginx_config diff --git a/scripts/restore b/scripts/restore index 8c11af6..143cb38 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,35 +1,41 @@ #!/bin/bash -# Note: each files and directories you've saved using the ynh_backup helper -# will be located in the current directory, regarding the last argument. - -# Exit on command errors and treat unset variables as an error -set -eu - -# See comments in install script -app=$YNH_APP_INSTANCE_NAME - # Source YunoHost helpers source /usr/share/yunohost/helpers +source ../settings/scripts/_common.sh + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +export app=$YNH_APP_INSTANCE_NAME # Retrieve old app settings -domain=$(ynh_app_setting_get "$app" domain) -path_url=$(ynh_app_setting_get "$app" path_url) +ynh_get_and_export domain path_url is_public final_path -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path_url}" +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Check if the app can be installed with this args +ynh_final_path_available + +# Install dependency +ynh_install_app_dependencies $pkg_dependencies # Restore sources & data -src_path="/var/www/${app}" -sudo cp -a ./sources "$src_path" +ynh_restore # Restore permissions to app files -# you may need to make some file and/or directory writeable by www-data (nginx user) -sudo chown -R root: "$src_path" +ynh_set_default_perm "$final_path" -# Restore NGINX configuration -sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +# If app is public, add url to SSOWat conf as skipped_uris +ynh_sso_access "/" # Restart webserver -sudo service nginx reload +systemctl reload nginx + +# Send message to the admin +message="If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/svgedit_ynh" + +ynh_send_readme_to_admin "$message" diff --git a/scripts/upgrade b/scripts/upgrade index 12e0d44..9111ce4 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,58 +1,54 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu - -# See comments in install script -app=$YNH_APP_INSTANCE_NAME - # Source YunoHost helpers source /usr/share/yunohost/helpers +source _common.sh + +# See comments in install script +export app=$YNH_APP_INSTANCE_NAME # Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) -path_url=$(ynh_app_setting_get "$app" path) -is_public=$(ynh_app_setting_get "$app" is_public) +ynh_get_and_export domain path_url is_public final_path -# Remove trailing "/" for next commands -path_url=${path_url%/} +# Check version +ynh_abort_if_up_to_date -# Check needed packages -if ! ynh_package_is_installed "wget" ; then - apt-get install -y wget -fi -if ! ynh_package_is_installed "unzip" ; then - apt-get install -y unzip +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Step migration +version=${version:-2.8.1} +if ynh_version_le "2.8.1" ; then + final_path=${final_path:-/var/www/$app} + ynh_app_setting_set "$app" final_path "$final_path" + + # Install dependency properly + ynh_install_app_dependencies $pkg_dependencies fi # Copy source files -src_path=/var/www/$app -sudo mkdir -p $src_path -mkdir ../sources/ -cd ../sources/ -wget -q https://github.com/SVG-Edit/svgedit/releases/download/svg-edit-2.8.1/svg-edit-2.8.1.zip -unzip svg-edit-2.8.1.zip -cd - -sudo rm -rf $src_path/* -sudo cp -a ../sources/svg-edit-2.8.1/. $src_path -rm -rf ../sources/svg-edit-2.8.1/ ../sources/svg-edit-2.8.1.zip -touch $src_path/config.js $src_path/custom.css +ynh_secure_remove $final_path +ynh_setup_source "$final_path" + +# Custom instructions +ynh_configure config.js "$final_path/config.js" +ynh_configure custom.css "$final_path/custom.css" # Set permissions to app files -# you may need to make some file and/or directory writeable by www-data (nginx user) -sudo chown -R root: $src_path - -# Modify Nginx configuration file and copy it to Nginx conf directory -nginx_conf=../conf/nginx.conf -sed -i "s@YNH_WWW_PATH@$path_url@g" $nginx_conf -sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf -sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf +ynh_set_default_perm "$final_path" # If app is public, add url to SSOWat conf as skipped_uris -if [[ $is_public -eq 1 ]]; then - # See install script - ynh_app_setting_set "$app" unprotected_uris "/" -fi +ynh_sso_access "/" -# Reload nginx service -sudo service nginx reload +# Set up nginx configuration +ynh_add_nginx_config