From beb4896e52b21664cfb27c8ce1bd4ff6ddfdeb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Mon, 25 Sep 2017 22:21:03 +0200 Subject: [PATCH] Solve issue https://github.com/YunoHost-Apps/synapse_ynh/issues/19 --- README.md | 10 +++++- manifest.json | 2 +- scripts/_common.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/upgrade | 7 ++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af916a7..9271a3d 100644 --- a/README.md +++ b/README.md @@ -55,4 +55,12 @@ https://github.com/vector-im/riot-web/issues/1977 for more details. - Doc (issue about domain) - Test arm - Riot doc -- Test production \ No newline at end of file +- Test production + +Todo for official App +====================== + +- Improve the upgrade from old version (all feedback is welcome) +- Improve documentation + + diff --git a/manifest.json b/manifest.json index c639014..e97d4a9 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "id": "synapse", "packaging_format": 1, "requirements": { - "yunohost": ">= 2.6.4" + "yunohost": ">= 2.7.2" }, "description": { "en": "Instant messaging server who use matrix", diff --git a/scripts/_common.sh b/scripts/_common.sh index 39c9cc6..86183a1 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -125,3 +125,92 @@ set_access() { # example : set_access USER FILE fi done } + + +####### Solve issue + +# Install package(s) +# +# usage: ynh_package_install name [name [...]] +# | arg: name - the package name to install +ynh_package_try_install() { + ynh_apt -o Dpkg::Options::=--force-confdef \ + -o Dpkg::Options::=--force-confold install $@ +} + + +# Build and install a package from an equivs control file +# +# example: generate an empty control file with `equivs-control`, adjust its +# content and use helper to build and install the package: +# ynh_package_install_from_equivs /path/to/controlfile +# +# usage: ynh_package_install_from_equivs controlfile +# | arg: controlfile - path of the equivs control file +ynh_package_install_from_equivs () { + controlfile=$1 + + # Check if the equivs package is installed. Or install it. + ynh_package_is_installed 'equivs' \ + || ynh_package_install equivs + + # retrieve package information + pkgname=$(grep '^Package: ' $controlfile | cut -d' ' -f 2) # Retrieve the name of the debian package + pkgversion=$(grep '^Version: ' $controlfile | cut -d' ' -f 2) # And its version number + [[ -z "$pkgname" || -z "$pkgversion" ]] \ + && echo "Invalid control file" && exit 1 # Check if this 2 variables aren't empty. + + # Update packages cache + ynh_package_update + + # Build and install the package + TMPDIR=$(mktemp -d) + # Note that the cd executes into a sub shell + # Create a fake deb package with equivs-build and the given control file + # Install the fake package without its dependencies with dpkg + # Install missing dependencies with ynh_package_install + (cp "$controlfile" "${TMPDIR}/control" && cd "$TMPDIR" \ + && equivs-build ./control 1>/dev/null \ + && sudo dpkg --force-depends \ + -i "./${pkgname}_${pkgversion}_all.deb" 2>&1 \ + && ynh_package_try_install -f) + [[ -n "$TMPDIR" ]] && rm -rf $TMPDIR # Remove the temp dir. + + # check if the package is actually installed + ynh_package_is_installed "$pkgname" +} + +# Define and install dependencies with a equivs control file +# This helper can/should only be called once per app +# +# usage: ynh_install_app_dependencies dep [dep [...]] +# | arg: dep - the package name to install in dependence +ynh_install_app_dependencies () { + dependencies=$@ + manifest_path="../manifest.json" + if [ ! -e "$manifest_path" ]; then + manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. + dep_app=${app//_/-} # Replace all '_' by '-' + + if ynh_package_is_installed "${dep_app}-ynh-deps"; then + echo "A package named ${dep_app}-ynh-deps is already installed" >&2 + else + cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build +Section: misc +Priority: optional +Package: ${dep_app}-ynh-deps +Version: ${version} +Depends: ${dependencies// /, } +Architecture: all +Description: Fake package for ${app} (YunoHost app) dependencies + This meta-package is only responsible of installing its dependencies. +EOF + ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ + || (ynh_package_autopurge; ynh_die "Unable to install dependencies") # Install the fake package and its dependencies + rm /tmp/${dep_app}-ynh-deps.control + ynh_app_setting_set $app apt_dependencies $dependencies + fi +} + diff --git a/scripts/upgrade b/scripts/upgrade index 35e997b..3b1e34d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,6 +24,13 @@ turnserver_pwd=$(ynh_app_setting_get $app turnserver_pwd) systemctl stop matrix-synapse.service +ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_restore_upgradebackup +} + +ynh_abort_if_errors + if [[ -z $synapse_old_version ]] then # ynh_die "Update from this version is not available now. You need to wait for the next update."