#!/bin/bash

REV="$(uname -r)"
printf '%s\n' "current ${REV}"

images_to_remove=$(sudo dpkg --list 'linux-image*' | grep '^ii' \
  | awk '{ print $2 }' | grep -v "${REV}")

if test -z "${images_to_remove}"; then
  printf '%s\n' "${0##*/}: nothing to remove"
  exit 0
fi

set -o xtrace
sudo apt remove "${images_to_remove}"
