#!/bin/sh -e

version="$1"

command -v update-miniramfs > /dev/null || exit 0

# passing the kernel version is required
if [ -z "${version}" ]; then
	echo >&2 "W: miniramfs: ${DPKG_MAINTSCRIPT_PACKAGE:-kernel package} did not pass a version number"
	exit 2
fi

# exit if kernel does not need an initramfs
if [ "$INITRD" = 'No' ]; then
	exit 0
fi

# avoid running multiple times
if [ -n "$DEB_MAINT_PARAMS" ]; then
	eval set -- "$DEB_MAINT_PARAMS"
	if [ -z "$1" ] || [ "$1" != "configure" ]; then
		exit 0
	fi
fi

# we're good - create initramfs.
# shellcheck disable=SC2086
update-miniramfs -c -k "${version}" >&2
