#!/bin/bash # postinst script for nbd-client # # see: dh_installdeb(1) set -e . /usr/share/debconf/confmodule # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-deconfigure' `in-favour' # `removing' # # for details, see /usr/share/doc/packaging-manual/ # # quoting from the policy: # Any necessary prompting should almost always be confined to the # post-installation script, and should be protected with a conditional # so that unnecessary prompting doesn't happen if a package's # installation fails and the `postinst' is called with `abort-upgrade', # `abort-remove' or `abort-deconfigure'. translate_extra() { sep="\t" while [ ! -z "$1" ] do case "$1" in -b*) opt=$2 NBD_OPT="${NBD_OPT}${sep}bs=${opt}" shift ;; -t*) opt=$2 NBD_OPT="${NBD_OPT}${sep}timeout=${opt}" shift ;; -sdp|-S) NBD_OPT="${NBD_OPT}${sep}sdp" ;; -p*) NBD_OPT="${NBD_OPT}${sep}persist" ;; -unix|-u) NBD_OPT="${NBD_OPT}${sep}unix" ;; -swap|-s) NBD_OPT="${NBD_OPT}${sep}swap" ;; esac shift sep="," done } convert_from_sh() { if [ ! -e /etc/nbd-client ] then # nothing to convert from return fi local old_md5sum=$(dpkg-query -W -f='${Conffiles}' nbd-client | awk '/nbdtab/{print $2}') local new_md5sum=$(md5sum /etc/nbdtab) if [ "$old_md5sum" != "$new_md5sum" ] then # nbdtab locally modified return fi TMPFILE=$(mktemp /tmp/nbd-client.XXXXXX) . /etc/nbd-client # check if we may auto-generate if [ "$AUTO_GEN" == "n" ] then db_get nbd-client/no-auto-config db_go db_stop return fi # check for KILLALL, which isn't supported anymore if [ "$KILLALL" != "false" ] then db_get nbd-client/killal_set db_go db_stop return fi i=0 while [ ! -z "${NBD_TYPE[$i]}" ] do NBD_DEVICE[$i]=${NBD_DEVICE[$i]#/dev/} NBD_OPT="" translate_extra ${NBD_EXTRA[$i]} echo -e "${NBD_DEVICE[$i]}\t${NBD_HOST[$i]}\t${NBD_NAME[$i]}${NBD_OPT}" >> $TMPFILE i=$(( $i + 1 )) done mv $TMPFILE /etc/nbdtab chmod 644 /etc/nbdtab mv /etc/nbd-client /etc/nbd-client.old } case "$1" in configure) convert_from_sh # Invoke initramfs trigger if [ -f /$(which update-initramfs) ] then update-initramfs -u fi # Migrate sendsigs.omit.d file if [ -f /lib/init/rw/sendsigs.omit.d/nbd-client ] then mv /lib/init/rw/sendsigs.omit.d/nbd-client /run/sendsigs.omit.d fi ;; abort-upgrade|abort-remove|abort-deconfigure) # We need not do anything. ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 0 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. # Automatically added by dh_installinit/12.1.1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -x "/etc/init.d/nbd-client" ]; then update-rc.d nbd-client start 41 S . stop 34 0 6 . >/dev/null || exit 1 fi fi # End automatically added section exit 0