[Piuparts-commits] [piuparts] 06/07: scripts: factor out an is_installed() function

Holger Levsen holger at moszumanska.debian.org
Mon Nov 2 17:19:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit fa10d00bca1c92b920b7d37056c0155c561fed8f
Author: Andreas Beckmann <anbe at debian.org>
Date:   Mon Nov 2 17:43:01 2015 +0100

    scripts: factor out an is_installed() function
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
---
 .../scripts/post_distupgrade_base_cleanup           | 15 +++++++++++----
 custom-scripts/scripts/pre_distupgrade_exceptions   | 10 ++++++++++
 .../scripts/pre_distupgrade_zz_database-server      | 21 ++++++++++++++-------
 .../scripts/pre_remove_40_find_missing_md5sums      | 15 +++++++++++----
 .../scripts/pre_remove_50_find_missing_copyright    | 15 +++++++++++----
 5 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/custom-scripts/scripts/post_distupgrade_base_cleanup b/custom-scripts/scripts/post_distupgrade_base_cleanup
index d1b5605..698efa3 100755
--- a/custom-scripts/scripts/post_distupgrade_base_cleanup
+++ b/custom-scripts/scripts/post_distupgrade_base_cleanup
@@ -1,6 +1,16 @@
 #!/bin/sh
 set -e
 
+is_installed()
+{
+	local pkg="$1"
+	dpkg-query -s "$pkg" >/dev/null 2>&1 || return 1
+	local status="$(dpkg-query -W -f '${Status}' $pkg)"
+	test "$status" != "unknown ok not-installed" || return 1
+	test "$status" != "deinstall ok config-files" || return 1
+	return 0
+}
+
 #
 # Remove obsolete base packages from the reference chroot.
 #
@@ -22,10 +32,7 @@ mark_for_purge()
 	pkg="$1"
 
 	# skip if the package is not installed
-	dpkg-query -s "$pkg" >/dev/null 2>&1 || return 0
-	status="$(dpkg-query -W -f '${Status}' $pkg)"
-	test "$status" != "unknown ok not-installed" || return 0
-	test "$status" != "deinstall ok config-files" || return 0
+	is_installed "$pkg" || return 0
 
 	case ${PIUPARTS_OBJECTS%%=*} in
 		$pkg)
diff --git a/custom-scripts/scripts/pre_distupgrade_exceptions b/custom-scripts/scripts/pre_distupgrade_exceptions
index d75aba6..24e715e 100755
--- a/custom-scripts/scripts/pre_distupgrade_exceptions
+++ b/custom-scripts/scripts/pre_distupgrade_exceptions
@@ -5,6 +5,16 @@ log_debug() {
 	echo "Debug: piuparts exception for package $PIUPARTS_OBJECTS"
 }
 
+is_installed()
+{
+	local pkg="$1"
+	dpkg-query -s "$pkg" >/dev/null 2>&1 || return 1
+	local status="$(dpkg-query -W -f '${Status}' $pkg)"
+	test "$status" != "unknown ok not-installed" || return 1
+	test "$status" != "deinstall ok config-files" || return 1
+	return 0
+}
+
 if [ "$PIUPARTS_DISTRIBUTION_NEXT" = "squeeze" ]; then
 
 	case ${PIUPARTS_OBJECTS%%=*} in
diff --git a/custom-scripts/scripts/pre_distupgrade_zz_database-server b/custom-scripts/scripts/pre_distupgrade_zz_database-server
index 35fe3e7..6290d91 100755
--- a/custom-scripts/scripts/pre_distupgrade_zz_database-server
+++ b/custom-scripts/scripts/pre_distupgrade_zz_database-server
@@ -1,6 +1,16 @@
 #!/bin/sh
 set -e
 
+is_installed()
+{
+	local pkg="$1"
+	dpkg-query -s "$pkg" >/dev/null 2>&1 || return 1
+	local status="$(dpkg-query -W -f '${Status}' $pkg)"
+	test "$status" != "unknown ok not-installed" || return 1
+	test "$status" != "deinstall ok config-files" || return 1
+	return 0
+}
+
 # Skip while creating the reference chroot.
 if [ "$PIUPARTS_PHASE" = "" ]; then
 	exit 0
@@ -32,13 +42,10 @@ esac
 
 for pkg in $CANDIDATES
 do
-	# skip if the package is not installed
-	dpkg-query -s "$pkg" >/dev/null 2>&1 || continue
-	status="$(dpkg-query -W -f '${Status}' $pkg)"
-	test "$status" != "unknown ok not-installed" || continue
-	test "$status" != "deinstall ok config-files" || continue
-
-	PACKAGES="$PACKAGES $pkg"
+	if is_installed "$pkg"
+	then
+		PACKAGES="$PACKAGES $pkg"
+	fi
 done
 
 if [ -n "$PACKAGES" ]
diff --git a/custom-scripts/scripts/pre_remove_40_find_missing_md5sums b/custom-scripts/scripts/pre_remove_40_find_missing_md5sums
index ccb6e08..b8aa444 100755
--- a/custom-scripts/scripts/pre_remove_40_find_missing_md5sums
+++ b/custom-scripts/scripts/pre_remove_40_find_missing_md5sums
@@ -1,16 +1,23 @@
 #!/bin/sh
 set -e
 
+is_installed()
+{
+	local pkg="$1"
+	dpkg-query -s "$pkg" >/dev/null 2>&1 || return 1
+	local status="$(dpkg-query -W -f '${Status}' $pkg)"
+	test "$status" != "unknown ok not-installed" || return 1
+	test "$status" != "deinstall ok config-files" || return 1
+	return 0
+}
+
 # skip the md5sum check if /usr/share/doc is pruned
 test ! -f /etc/dpkg/dpkg.cfg.d/piuparts-path-exclude || exit 0
 
 for pkg in ${PIUPARTS_OBJECTS%%=*}
 do
 	# skip check if the package is not installed
-	dpkg-query -s "$pkg" >/dev/null 2>&1 || continue
-	status="$(dpkg-query -W -f '${Status}' $pkg)"
-	test "$status" != "unknown ok not-installed" || continue
-	test "$status" != "deinstall ok config-files" || continue
+	is_installed "$pkg" || continue
 
 	md5file="/var/lib/dpkg/info/$pkg.md5sums"
 	test -f "$md5file" || md5file="/var/lib/dpkg/info/$pkg:$(dpkg --print-architecture).md5sums"
diff --git a/custom-scripts/scripts/pre_remove_50_find_missing_copyright b/custom-scripts/scripts/pre_remove_50_find_missing_copyright
index e4e5a53..94172ac 100755
--- a/custom-scripts/scripts/pre_remove_50_find_missing_copyright
+++ b/custom-scripts/scripts/pre_remove_50_find_missing_copyright
@@ -1,6 +1,16 @@
 #!/bin/sh
 set -e
 
+is_installed()
+{
+	local pkg="$1"
+	dpkg-query -s "$pkg" >/dev/null 2>&1 || return 1
+	local status="$(dpkg-query -W -f '${Status}' $pkg)"
+	test "$status" != "unknown ok not-installed" || return 1
+	test "$status" != "deinstall ok config-files" || return 1
+	return 0
+}
+
 failed=
 for pkg in ${PIUPARTS_OBJECTS%%=*}
 do
@@ -20,10 +30,7 @@ do
 	esac
 
 	# skip check if the package is not installed
-	dpkg-query -s "$pkg" >/dev/null 2>&1 || continue
-	status="$(dpkg-query -W -f '${Status}' $pkg)"
-	test "$status" != "unknown ok not-installed" || continue
-	test "$status" != "deinstall ok config-files" || continue
+	is_installed "$pkg" || continue
 
 	docdir="/usr/share/doc/$pkg"
 	copyright="$docdir/copyright"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list