#!/bin/sh set -e FILENAME="/etc/kernel/postinst.d/kdump-tools" DIVERTED_FILENAME="${FILENAME}.distrib" # Shamelessly stolen from udev's postinst chrooted() { if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then # the devicenumber/inode pair of / is the same as that of /sbin/init's # root, so we're *not* in a chroot and hence return false. return 1 fi echo "A chroot environment has been detected." return 0 } case "$1" in configure) KVER=$(uname -r) if chrooted; then # If we are in a chroot then figure out the kernel version # in a different way. There could be multiple kernels installed # so this is not fool-proof KVER=$(dpkg-query -W -f='${binary:Package}\n' linux-image-* | head -n 1 | sed 's/linux-image-//') fi if [ ! -z ${KVER} ]; then if [ -e /var/lib/kdump/initrd.img-${KVER} ]; then echo "Backing up /var/lib/kdump/initrd.img-${KVER}" cp -pr /var/lib/kdump/initrd.img-${KVER} /var/lib/kdump/initrd.img-${KVER}.distrib fi echo "Running /etc/kernel/postinst.d/kdump-tools ${KVER}" /etc/kernel/postinst.d/kdump-tools ${KVER} ||: fi # Make sure our .distrib is there so that our postrm scripts # do the right thing if [ ! -f ${DIVERTED_FILENAME} ]; then if [ -f ${FILENAME} ]; then cp -f ${FILENAME} ${DIVERTED_FILENAME} ||: fi fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac exit 0