#! /bin/sh

set -eux

# We install kdump-tools in the minimal layer but it's enabled by default.
# subiquity/curtin will later decide to either keep it enabled or disable it
# in the target system, but let's ensure it's disabled in the live layer.
# We do this by manually modifying /etc/default/kdump-tools to use USE_KDUMP=0.
# Without this, kdump-tools is still technically disabled since it requires both:
#  1. crashkernel on the kernel command line
#  2. USE_KDUMP=1 in /etc/default/kdump-tools
# and the kernel command line in the live layer doesn't have the crashkernel
# parameter in the kernel command line, but this semi-disabled state isn't
# ideal. So let's be doubly sure and set USE_KDUMP=0.
#
# Note that kdump-tools relies on ucf for configuration file management. So
# while we could modify the value in the minimal layer, doing so in a way that
# doesn't make future dpkg-reconfigures hard is a huge hassle. You also have
# to make sure to do the same steps to every layer it may get included.

case ${PASS:-} in
    *.live)
        ;;
    *)
        exit 0
        ;;
esac

sed -i 's/USE_KDUMP=1/USE_KDUMP=0/' /etc/default/kdump-tools