1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!/bin/sh
set -e
kversion="$1"
vmlinuz="${2:-/boot/vmlinuz-$kversion}"
set -- $DEB_MAINT_PARAMS
action="$1"
version="$2"
# Disable if our package is not installed.
if ! command -v depthchargectl >/dev/null 2>&1; then
echo "Not removing depthcharge image, depthchargectl is missing." >&2
exit 0
fi
# Ignore errors if we're not booted with depthcharge
maybe_error() {
if grep "cros_secure" /proc/cmdline >/dev/null 2>&1; then
echo "Failed to remove depthcharge image, system may be unbootable." >&2
exit 1
else
echo "Not booted with depthcharge, so ignoring that." >&2
exit 0
fi
}
# Disable based on package configuration
enabled="$(
depthchargectl config \
--section depthchargectl/remove \
--default False \
enable-system-hooks 2>/dev/null
)"
if [ "$enabled" != "True" ]; then
echo "Not removing depthcharge image, disabled by config." >&2
exit 0
fi
images_dir="$(
depthchargectl config \
--section depthchargectl/remove \
--default /boot/depthcharge \
images-dir 2>/dev/null
)"
# Run only once at the end.
case "$action" in
"remove"|"'remove'"|'')
# We are either not removing the running kernel, or the user has
# explicitly agreed to removing the running kernel.
if [ -f "${images_dir}/${kversion}.img" ]; then
echo "Running depthchargectl remove --force '$kversion':" >&2
depthchargectl remove --force "$kversion" >/dev/null \
|| maybe_error
else
echo "Not removing depthcharge image, already doesn't exist." >&2
exit 0
fi
;;
esac
|