Prevent Debian package upgrades from prompting.
authorBen Pfaff <blp@nicira.com>
Mon, 5 Jan 2009 18:52:57 +0000 (10:52 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 5 Jan 2009 18:52:57 +0000 (10:52 -0800)
Before, we were using dpkg "conffiles" for our configuration.  This means
that if the admin has customized the configuration (as is necessary to
make the switch work) and the default configuration included in the package
changed, then dpkg would prompt the user interactively about what to do.

Now, we take responsibility for creating, upgrading, and removing the
configuration file ourselves, and do not prompt.

debian/ofp-switch-setup
debian/openflow-switch.dirs
debian/openflow-switch.postinst [new file with mode: 0755]
debian/openflow-switch.postrm [new file with mode: 0755]
debian/openflow-switch.template [moved from debian/openflow-switch.default with 100% similarity]
debian/rules

index c21f1e0..5a999ab 100755 (executable)
@@ -14,6 +14,7 @@ use warnings;
 my $debconf_owner = 'openflow-switch';
 
 my $default = '/etc/default/openflow-switch';
+my $template = '/usr/share/openflow/switch/default.template';
 my $etc = '/etc/openflow-switch';
 my $rundir = '/var/run';
 my $privkey_file = "$etc/of0-privkey.pem";
@@ -62,6 +63,8 @@ if (-e $default) {
         local $_ = $oldconfig{$key};
         &{$map{$key}}() if defined && !/^\s*$/;
     }
+} elsif (-e $template) {
+    %oldconfig = load_config($template);
 }
 
 my $cacert_preverified = -e $cacert_file;
index 6cf04b5..a53002f 100644 (file)
@@ -1 +1,2 @@
 /etc/openflow-switch
+/usr/share/openflow/switch
diff --git a/debian/openflow-switch.postinst b/debian/openflow-switch.postinst
new file mode 100755 (executable)
index 0000000..6e75786
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+# postinst script for openflow-switch
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <postinst> `abort-remove'
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    configure)
+       DEFAULT=/etc/default/openflow-switch
+       TEMPLATE=/usr/share/openflow/switch/default.template
+       if ! test -e $DEFAULT; then
+           cp $TEMPLATE $DEFAULT
+       elif ! grep DATAPATH_ID $DEFAULT; then
+           echo >> $DEFAULT
+           sed -n '/DATAPATH_ID:/,/DATAPATH_ID=/p' $TEMPLATE >> $DEFAULT
+       fi
+        ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
+        ;;
+
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+        ;;
+esac
+
+#DEBHELPER#
+
+exit 0
+
+
diff --git a/debian/openflow-switch.postrm b/debian/openflow-switch.postrm
new file mode 100755 (executable)
index 0000000..20bab0e
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+# postrm script for openflow-switch
+#
+# 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
+
+
+case "$1" in
+    purge)
+       rm -f /etc/default/openflow-switch
+       ;;
+
+    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.
+
+#DEBHELPER#
+
+exit 0
+
+
index fa3cea8..539c8f3 100755 (executable)
@@ -125,6 +125,7 @@ install-arch: build-arch
        dh_installdirs -s
        $(MAKE) -C _debian DESTDIR=$(CURDIR)/debian/openflow install
        cp debian/openflow-switch-config.overrides debian/openflow-switch-config/usr/share/lintian/overrides/openflow-switch-config
+       cp debian/openflow-switch.template debian/openflow-switch/usr/share/openflow/switch/default.template
        dh_install -s
        $(ext_install_arch)