From d98b5e036c582c1f9040269c1fae70dffc9971ea Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Wed, 8 Feb 2017 19:23:27 +0100 Subject: [PATCH 1/9] [enh] New helpers for equivs use - `ynh_package_remove` and `ynh_package_autoremove` were just moved up. - Small modifications on `ynh_package_install_from_equivs`. Just added some comments and used popd instead of cd. - Added `ynh_app_dependencies` to manage easily installation of dependencies with equivs - And `ynh_remove_app_dependencies` to remove them. --- data/helpers.d/package | 111 +++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 38 deletions(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index 6dd42ff65..71aabdb67 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -47,44 +47,6 @@ ynh_package_install() { -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 - - # install equivs package as needed - ynh_package_is_installed 'equivs' \ - || ynh_package_install equivs - - # retrieve package information - pkgname=$(grep '^Package: ' $controlfile | cut -d' ' -f 2) - pkgversion=$(grep '^Version: ' $controlfile | cut -d' ' -f 2) - [[ -z "$pkgname" || -z "$pkgversion" ]] \ - && echo "Invalid control file" && exit 1 - - # update packages cache - ynh_package_update - - # build and install the package - TMPDIR=$(ynh_mkdir_tmp) - (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_install -f) \ - && ([[ -n "$TMPDIR" ]] && rm -rf $TMPDIR) - - # check if the package is actually installed - ynh_package_is_installed "$pkgname" -} - # Remove package(s) # # usage: ynh_package_remove name [name [...]] @@ -100,3 +62,76 @@ ynh_package_remove() { ynh_package_autoremove() { ynh_apt autoremove $@ } + +# 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=$(ynh_mkdir_tmp) + cp "$controlfile" "${TMPDIR}/control" && pushd "$TMPDIR" # pushd is like a cd, but it stores the previous directory + # 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 + equivs-build ./control 1>/dev/null \ + && sudo dpkg --force-depends \ + -i "./${pkgname}_${pkgversion}_all.deb" 2>&1 \ + && ynh_package_install -f + [[ -n "$TMPDIR" ]] && rm -rf $TMPDIR # Remove the temp dir. + + # check if the package is actually installed + ynh_package_is_installed "$pkgname" + popd # Like a cd on the directory stored by pushd +} + +# Install dependencies with a equivs control file +# +# usage: ynh_app_dependencies dep [dep [...]] +# | arg: dep - the package name to install in dependence +ynh_app_dependencies () { + dependencies=$1 + version=$(sudo python3 -c "import sys, json;print(json.load(open('../manifest.json'))['version'])") # Retrieve the version number in the manifest file. + dep_app=${app/_/-} # Replace all '_' by '-' + cat > ./${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 ./${dep_app}-ynh-deps.control \ + || ynh_die "Unable to install dependencies" # Install the fake package and its dependencies +} + +# Remove fake package and its dependencies +# +# Dependencies will removed only if no other package need them. +# +# usage: ynh_remove_app_dependencies +ynh_remove_app_dependencies () { + dep_app=${app/_/-} # Replace all '_' by '-' + ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used. +} From 0989e27d584c394b9dfa92928ebced0642aef81d Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 9 Feb 2017 17:22:24 +0100 Subject: [PATCH 2/9] Update package --- data/helpers.d/package | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index 71aabdb67..3b29a1f3d 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -109,8 +109,12 @@ ynh_package_install_from_equivs () { # usage: ynh_app_dependencies dep [dep [...]] # | arg: dep - the package name to install in dependence ynh_app_dependencies () { - dependencies=$1 - version=$(sudo python3 -c "import sys, json;print(json.load(open('../manifest.json'))['version'])") # Retrieve the version number in the manifest file. + 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=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file. dep_app=${app/_/-} # Replace all '_' by '-' cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build Section: misc From b062c014b0dfb0cf89a5a11ab051c456a564b414 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 9 Feb 2017 18:35:18 +0100 Subject: [PATCH 3/9] Restore use of subshell --- data/helpers.d/package | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index 3b29a1f3d..9cafd3970 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -89,19 +89,19 @@ ynh_package_install_from_equivs () { # Build and install the package TMPDIR=$(ynh_mkdir_tmp) - cp "$controlfile" "${TMPDIR}/control" && pushd "$TMPDIR" # pushd is like a cd, but it stores the previous directory + # 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 - equivs-build ./control 1>/dev/null \ + (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_install -f + && ynh_package_install -f) [[ -n "$TMPDIR" ]] && rm -rf $TMPDIR # Remove the temp dir. # check if the package is actually installed ynh_package_is_installed "$pkgname" - popd # Like a cd on the directory stored by pushd } # Install dependencies with a equivs control file From 7ade94e7e319fae635c1caede0e10f820c816ca8 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 2 Mar 2017 23:55:28 +0100 Subject: [PATCH 4/9] Fix ynh_app_dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Double // pour remplacer toutes les occurrences de _ Ajout d'une virgule entre les dépendances. --- data/helpers.d/package | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index 9cafd3970..7264920ce 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -115,13 +115,13 @@ ynh_app_dependencies () { manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place fi version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file. - dep_app=${app/_/-} # Replace all '_' by '-' + dep_app=${app//_/-} # Replace all '_' by '-' cat > ./${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} +Depends: ${dependencies// /, } Architecture: all Description: Fake package for ${app} (YunoHost app) dependencies This meta-package is only responsible of installing its dependencies. From 4dfde86e1a8502667271eb23e764d936af9c0d6f Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 2 Mar 2017 23:57:02 +0100 Subject: [PATCH 5/9] Fix ynh_remove_app_dependencies too... --- data/helpers.d/package | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index 7264920ce..404c63cbc 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -136,6 +136,6 @@ EOF # # usage: ynh_remove_app_dependencies ynh_remove_app_dependencies () { - dep_app=${app/_/-} # Replace all '_' by '-' + dep_app=${app//_/-} # Replace all '_' by '-' ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used. } From 5fcb8cd439c3725beb46ada423ac046a812fde91 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 14 Mar 2017 16:34:07 +0100 Subject: [PATCH 6/9] Remove use of deprecated helper --- data/helpers.d/package | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index 404c63cbc..c9f0557cc 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -88,7 +88,7 @@ ynh_package_install_from_equivs () { ynh_package_update # Build and install the package - TMPDIR=$(ynh_mkdir_tmp) + 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 From 2bb32c26b64f274380adafaefbf877667ac3e092 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 14 Mar 2017 18:05:28 +0100 Subject: [PATCH 7/9] Add app setting --- data/helpers.d/package | 1 + 1 file changed, 1 insertion(+) diff --git a/data/helpers.d/package b/data/helpers.d/package index c9f0557cc..c87abe5f3 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -128,6 +128,7 @@ Description: Fake package for ${app} (YunoHost app) dependencies EOF ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \ || ynh_die "Unable to install dependencies" # Install the fake package and its dependencies + ynh_app_setting_set $app apt_dependencies $dependencies } # Remove fake package and its dependencies From 5f3fcefc882c66ccb7cd60b05fef6cde3d4f81d0 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 16 Mar 2017 18:35:57 +0100 Subject: [PATCH 8/9] Prevent to rewrite the previous control file --- data/helpers.d/package | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index c87abe5f3..2bf258c53 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -116,7 +116,11 @@ ynh_app_dependencies () { fi version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file. dep_app=${app//_/-} # Replace all '_' by '-' - cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build + + if ynh_package_is_installed "${dep_app}-ynh-deps"; then + echo "A package named ${dep_app}-ynh-deps is already installed" >&2 + else + cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build Section: misc Priority: optional Package: ${dep_app}-ynh-deps @@ -126,9 +130,10 @@ 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 ./${dep_app}-ynh-deps.control \ - || ynh_die "Unable to install dependencies" # Install the fake package and its dependencies - ynh_app_setting_set $app apt_dependencies $dependencies + ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \ + || ynh_die "Unable to install dependencies" # Install the fake package and its dependencies + ynh_app_setting_set $app apt_dependencies $dependencies + fi } # Remove fake package and its dependencies From 5b9092d6df5c6985979d353a99dd8f5bacef40c8 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 17 Mar 2017 04:07:17 +0100 Subject: [PATCH 9/9] Rename ynh_app_dependencies to ynh_install_app_dependencies --- data/helpers.d/package | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/data/helpers.d/package b/data/helpers.d/package index 2bf258c53..368e61cd6 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -104,11 +104,12 @@ ynh_package_install_from_equivs () { ynh_package_is_installed "$pkgname" } -# Install dependencies with a equivs control file +# Define and install dependencies with a equivs control file +# This helper can/should only be called once per app # -# usage: ynh_app_dependencies dep [dep [...]] +# usage: ynh_install_app_dependencies dep [dep [...]] # | arg: dep - the package name to install in dependence -ynh_app_dependencies () { +ynh_install_app_dependencies () { dependencies=$@ manifest_path="../manifest.json" if [ ! -e "$manifest_path" ]; then