[pkg-bacula-commits] [bacula] 01/01: rewrite of postrm scripts, step one

Carsten Leonhardt leo at moszumanska.debian.org
Wed Aug 31 14:21:16 UTC 2016


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

leo pushed a commit to branch migrate-files
in repository bacula.

commit 3a59c8130998f4537592c6ab97d51b15020b4528
Author: Carsten Leonhardt <leo at debian.org>
Date:   Wed Aug 31 16:17:59 2016 +0200

    rewrite of postrm scripts, step one
    
    all the repetition is rather dumb, TODO lists better solutions
---
 debian/TODO                     |  5 +++
 debian/bacula-console-qt.postrm | 59 ++++++++++++++++++++++++---
 debian/bacula-console.postrm    | 59 +++++++++++++++++++++++----
 debian/bacula-director.postrm   | 88 +++++++++++++++++++++++------------------
 debian/bacula-fd.postrm         | 86 ++++++++++++++++++++++++----------------
 debian/bacula-sd.postrm         | 85 +++++++++++++++++++++++----------------
 debian/changelog                |  1 +
 debian/scripts/libpostrm.inc.sh | 40 +++++++++++++++++++
 8 files changed, 306 insertions(+), 117 deletions(-)

diff --git a/debian/TODO b/debian/TODO
index d7834ce..aec13e0 100644
--- a/debian/TODO
+++ b/debian/TODO
@@ -17,6 +17,11 @@ Normal:
  * Check if bacula-director-pgsql suggesting postgresql-contrib is useful
  * Automatically detect the introduction of a new database version and
    warn or abort package build
+ * Automate including libpostrm.inc.sh in the relevant postrm scripts
+   (sed '/XX_libpostrm_XX/r scripts/libpostrm.inc.sh')
+   Better: autogenerate the postrm scripts, maybe from information in
+   <package>.ucfconfpurge/<package>.confpurge or something like that
+   Ideally, this would become a debhelper script ...
 
 Minor:
 
diff --git a/debian/bacula-console-qt.postrm b/debian/bacula-console-qt.postrm
index 0b24c1c..cc04e7c 100644
--- a/debian/bacula-console-qt.postrm
+++ b/debian/bacula-console-qt.postrm
@@ -1,14 +1,63 @@
-#! /bin/sh
+#!/bin/sh
 
 set -e
 
+CONFFILE=/etc/bacula/bat.conf
+
+# start of libpostrm.inc.sh
+#
+# helper functions to purge conffiles
+# with and without ucf deregistration
+#
+# this file must be inserted into the postrm scripts, as there we
+# can't rely on files from our packages (they are probably already
+# deleted).
+
+# delete a list of files, also with known backup extensions
+purge_conf() {
+    local file ext
+
+    for file in $@; do
+	rm -f $file
+	for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist .dist; do
+	    rm -f $file$ext
+	done
+    done
+}
+
+# unregister a list of conffiles from ucf after deleting them
+# usage: purge_ucf_conf <packagename> <conffile ...>
+purge_ucf_conf() {
+    local package file
+
+    # save package name
+    package=$1
+    # remove first argument from list
+    shift
+
+    purge_conf $@
+    if [ -x `which ucf` ]; then
+	for file in $@; do
+	    ucf --purge $file
+	    ucfr --purge $package $file
+	done
+    fi
+}
+# end of libpostrm.inc.sh
 
 case "$1" in
-  purge)
-    rm -f /etc/bacula/bat.conf /etc/bacula/bat.conf.*
-  ;;
-esac
+    purge)
+	purge_conf $CONFFILE
+	;;
 
+    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+	;;
+
+    *)
+	echo "postrm called with unknown argument \`$1'" >&2
+	exit 1
+	;;
+esac
 
 # dh_installdeb will replace this with shell code automatically
 # generated by other debhelper scripts.
diff --git a/debian/bacula-console.postrm b/debian/bacula-console.postrm
index 39ab422..a1d7a97 100644
--- a/debian/bacula-console.postrm
+++ b/debian/bacula-console.postrm
@@ -1,18 +1,63 @@
-#! /bin/sh
+#!/bin/sh
 
 set -e
 
+CONFFILE=/etc/bacula/bconsole.conf
 
-CONSOLE=/usr/sbin/bacula-console
-CFGDIR=/etc/bacula
-CFGFILE="bconsole.conf"
+# start of libpostrm.inc.sh
+#
+# helper functions to purge conffiles
+# with and without ucf deregistration
+#
+# this file must be inserted into the postrm scripts, as there we
+# can't rely on files from our packages (they are probably already
+# deleted).
+
+# delete a list of files, also with known backup extensions
+purge_conf() {
+    local file ext
+
+    for file in $@; do
+	rm -f $file
+	for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist .dist; do
+	    rm -f $file$ext
+	done
+    done
+}
+
+# unregister a list of conffiles from ucf after deleting them
+# usage: purge_ucf_conf <packagename> <conffile ...>
+purge_ucf_conf() {
+    local package file
+
+    # save package name
+    package=$1
+    # remove first argument from list
+    shift
+
+    purge_conf $@
+    if [ -x `which ucf` ]; then
+	for file in $@; do
+	    ucf --purge $file
+	    ucfr --purge $package $file
+	done
+    fi
+}
+# end of libpostrm.inc.sh
 
 case "$1" in
-	purge)
-		rm -f $CFGDIR/$CFGFILE $CFGDIR/$CFGFILE.*
+    purge)
+	purge_conf $CONFFILE
+	;;
+
+    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
 	;;
-esac
 
+    *)
+	echo "postrm called with unknown argument \`$1'" >&2
+	exit 1
+	;;
+esac
 
 # dh_installdeb will replace this with shell code automatically
 # generated by other debhelper scripts.
diff --git a/debian/bacula-director.postrm b/debian/bacula-director.postrm
index aa32a0d..a1fe0de 100644
--- a/debian/bacula-director.postrm
+++ b/debian/bacula-director.postrm
@@ -1,52 +1,64 @@
 #!/bin/sh
-# postrm script for bacula-director
-#
-# see: dh_installdeb(1)
 
 set -e
 
-# summary of how this script can be called:
-#        * <postrm> `remove'
-#        * <postrm> `purge'
-#        * <old-postrm> `upgrade' <new-version>
-#        * <new-postrm> `failed-upgrade' <old-version>
-#        * <new-postrm> `abort-install'
-#        * <new-postrm> `abort-install' <old-version>
-#        * <new-postrm> `abort-upgrade' <old-version>
-#        * <disappearer's-postrm> `disappear' <overwriter>
-#          <overwriter-version>
-# for details, see http://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
-
+PACKAGE=bacula-director
 CONFFILE=/etc/bacula/bacula-dir.conf
+UCF_CONFFILES=/etc/bacula/scripts/delete_catalog_backup
+
+# start of libpostrm.inc.sh
+#
+# helper functions to purge conffiles
+# with and without ucf deregistration
+#
+# this file must be inserted into the postrm scripts, as there we
+# can't rely on files from our packages (they are probably already
+# deleted).
+
+# delete a list of files, also with known backup extensions
+purge_conf() {
+    local file ext
+
+    for file in $@; do
+	rm -f $file
+	for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist .dist; do
+	    rm -f $file$ext
+	done
+    done
+}
+
+# unregister a list of conffiles from ucf after deleting them
+# usage: purge_ucf_conf <packagename> <conffile ...>
+purge_ucf_conf() {
+    local package file
+
+    # save package name
+    package=$1
+    # remove first argument from list
+    shift
+
+    purge_conf $@
+    if [ -x `which ucf` ]; then
+	for file in $@; do
+	    ucf --purge $file
+	    ucfr --purge $package $file
+	done
+    fi
+}
+# end of libpostrm.inc.sh
 
 case "$1" in
-	purge)
-		rm -f $CONFFILE $CONFFILE.dist
-
-		# purge all conffiles of this package that are
-		# registered through ucf (this cannot be put into
-		# common-functions.dpkg as it might be unavailable
-		# during purge)
-		PACKAGE=bacula-director
-		if [ -x `which ucfq` ]; then
-		    for conffile in $(ucfq -w $PACKAGE | cut -d: -f1); do
-			rm -f $conffile
-			for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist; do
-			    rm -f $conffile$ext
-			done
-			ucf --purge $conffile
-			ucfr --purge $PACKAGE $conffile
-		    done
-		fi
+    purge)
+	purge_conf $CONFFILE
+	purge_ucf_conf $PACKAGE $UCF_CONFFILES
 	;;
 
-	remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
 	;;
 
-	*)
-		echo "postrm called with unknown argument \`$1'" >&2
-		exit 1
+    *)
+	echo "postrm called with unknown argument \`$1'" >&2
+	exit 1
 	;;
 esac
 
diff --git a/debian/bacula-fd.postrm b/debian/bacula-fd.postrm
index 940b91f..a7b8df4 100644
--- a/debian/bacula-fd.postrm
+++ b/debian/bacula-fd.postrm
@@ -1,47 +1,65 @@
-#! /bin/sh
-# postrm script for bacula
-#
-# see: dh_installdeb(1)
+#!/bin/sh
 
 set -e
 
-# summary of how this script can be called:
-#        * <postrm> `remove'
-#        * <postrm> `purge'
-#        * <old-postrm> `upgrade' <new-version>
-#        * <new-postrm> `failed-upgrade' <old-version>
-#        * <new-postrm> `abort-install'
-#        * <new-postrm> `abort-install' <old-version>
-#        * <new-postrm> `abort-upgrade' <old-version>
-#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
-# for details, see http://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
+PACKAGE=bacula-fd
+CONFFILE=/etc/bacula/bacula-fd.conf
+UCF_CONFFILES=/etc/default/bacula-fd
 
+# start of libpostrm.inc.sh
+#
+# helper functions to purge conffiles
+# with and without ucf deregistration
+#
+# this file must be inserted into the postrm scripts, as there we
+# can't rely on files from our packages (they are probably already
+# deleted).
 
-case "$1" in
-	purge)
-		rm -f /etc/bacula/bacula-fd.*
-
-		# purge /etc/default/bacula-fd
-		rm -f /etc/default/bacula-fd /etc/default/bacula-fd.ucf-old \
-			/etc/default/bacula-fd.ucf-new /etc/default/bacula-fd.ucf-dist
-		if which ucf >/dev/null; then
-			ucf --purge /etc/default/bacula-fd
-		fi
-		if which ucfr >/dev/null; then
-			ucfr --purge bacula-fd /etc/default/bacula-fd
-		fi
-	;;
+# delete a list of files, also with known backup extensions
+purge_conf() {
+    local file ext
 
-	remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+    for file in $@; do
+	rm -f $file
+	for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist .dist; do
+	    rm -f $file$ext
+	done
+    done
+}
 
+# unregister a list of conffiles from ucf after deleting them
+# usage: purge_ucf_conf <packagename> <conffile ...>
+purge_ucf_conf() {
+    local package file
 
-        ;;
+    # save package name
+    package=$1
+    # remove first argument from list
+    shift
 
-    *)
-        echo "postrm called with unknown argument \`$1'" >&2
-        exit 1
+    purge_conf $@
+    if [ -x `which ucf` ]; then
+	for file in $@; do
+	    ucf --purge $file
+	    ucfr --purge $package $file
+	done
+    fi
+}
+# end of libpostrm.inc.sh
 
+case "$1" in
+    purge)
+	purge_conf $CONFFILE
+	purge_ucf_conf $PACKAGE $UCF_CONFFILES
+	;;
+
+    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+	;;
+
+    *)
+	echo "postrm called with unknown argument \`$1'" >&2
+	exit 1
+	;;
 esac
 
 # dh_installdeb will replace this with shell code automatically
diff --git a/debian/bacula-sd.postrm b/debian/bacula-sd.postrm
index 30c3059..6f5d8c3 100644
--- a/debian/bacula-sd.postrm
+++ b/debian/bacula-sd.postrm
@@ -1,46 +1,65 @@
-#! /bin/sh
-# postrm script for bacula
-#
-# see: dh_installdeb(1)
+#!/bin/sh
 
 set -e
 
-# summary of how this script can be called:
-#        * <postrm> `remove'
-#        * <postrm> `purge'
-#        * <old-postrm> `upgrade' <new-version>
-#        * <new-postrm> `failed-upgrade' <old-version>
-#        * <new-postrm> `abort-install'
-#        * <new-postrm> `abort-install' <old-version>
-#        * <new-postrm> `abort-upgrade' <old-version>
-#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
-# for details, see http://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
+PACKAGE=bacula-sd
+CONFFILE=/etc/bacula/bacula-sd.conf
+UCF_CONFFILES=/etc/default/bacula-sd
+
+# start of libpostrm.inc.sh
+#
+# helper functions to purge conffiles
+# with and without ucf deregistration
+#
+# this file must be inserted into the postrm scripts, as there we
+# can't rely on files from our packages (they are probably already
+# deleted).
+
+# delete a list of files, also with known backup extensions
+purge_conf() {
+    local file ext
+
+    for file in $@; do
+	rm -f $file
+	for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist .dist; do
+	    rm -f $file$ext
+	done
+    done
+}
 
+# unregister a list of conffiles from ucf after deleting them
+# usage: purge_ucf_conf <packagename> <conffile ...>
+purge_ucf_conf() {
+    local package file
+
+    # save package name
+    package=$1
+    # remove first argument from list
+    shift
+
+    purge_conf $@
+    if [ -x `which ucf` ]; then
+	for file in $@; do
+	    ucf --purge $file
+	    ucfr --purge $package $file
+	done
+    fi
+}
+# end of libpostrm.inc.sh
 
 case "$1" in
-	purge)
-		rm -f /etc/bacula/bacula-sd.*
-
-		# purge /etc/default/bacula-sd
-		rm -f /etc/default/bacula-sd /etc/default/bacula-sd.ucf-old \
-			/etc/default/bacula-sd.ucf-new /etc/default/bacula-sd.ucf-dist
-		if which ucf >/dev/null; then
-			ucf --purge /etc/default/bacula-sd
-		fi
-		if which ucfr >/dev/null; then
-			ucfr --purge bacula-sd /etc/default/bacula-sd
-		fi
+    purge)
+	purge_conf $CONFFILE
+	purge_ucf_conf $PACKAGE $UCF_CONFFILES
 	;;
 
-	remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
-
-        ;;
+    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+	;;
 
     *)
-        echo "postrm called with unknown argument \`$1'" >&2
-        exit 1
-
+	echo "postrm called with unknown argument \`$1'" >&2
+	exit 1
+	;;
 esac
 
 # dh_installdeb will replace this with shell code automatically
diff --git a/debian/changelog b/debian/changelog
index 5a62155..7acc136 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,7 @@
 bacula (7.4.3+dfsg-5) unstable; urgency=medium
 
   * Don't delete all of /etc/bacula when purging bacula-common
+  * Rewrote most of the postrm scripts
 
  --
 
diff --git a/debian/scripts/libpostrm.inc.sh b/debian/scripts/libpostrm.inc.sh
new file mode 100755
index 0000000..f2b0223
--- /dev/null
+++ b/debian/scripts/libpostrm.inc.sh
@@ -0,0 +1,40 @@
+# start of libpostrm.inc.sh
+#
+# helper functions to purge conffiles
+# with and without ucf deregistration
+#
+# this file must be inserted into the postrm scripts, as there we
+# can't rely on files from our packages (they are probably already
+# deleted).
+
+# delete a list of files, also with known backup extensions
+purge_conf() {
+    local file ext
+
+    for file in $@; do
+	echo rm -f $file
+	for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist .dist; do
+	    echo rm -f $file$ext
+	done
+    done
+}
+
+# unregister a list of conffiles from ucf after deleting them
+# usage: purge_ucf_conf <packagename> <conffile ...>
+purge_ucf_conf() {
+    local package file
+
+    # save package name
+    package=$1
+    # remove first argument from list
+    shift
+
+    purge_conf $@
+    if [ -x `which ucf` ]; then
+	for file in $@; do
+	    echo ucf --purge $file
+	    echo ucfr --purge $package $file
+	done
+    fi
+}
+# end of libpostrm.inc.sh

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



More information about the pkg-bacula-commits mailing list