#!/bin/bash
#                       /usr/local/bin/boot-minimize
# https://crystalfaeries.net/posix/bin/boot-minimize
# celeste:crystalfaery BOOT-MINIMIZE 2018-06-29 15:35:26+00:00
# From: https://www.linuxjournal.com/content/clearing-out-boot

echo "You are about to delete obsolete kernels from your /boot"			>&2
  sudo dpkg --purge								\
$(sudo dpkg --list "linux-image*"	|| exit $?				\
| grep -v $(uname -r	|| exit $?)	|| exit $?				\
| grep ii		|| exit $?						\
| awk '{ print $2 }'	|| exit $?)	|| exit $?

sudo update-grub2	|| exit $?
sudo apt-get -f install	|| exit $?
sudo apt-get autoremove	|| exit $?
exit	0		# i wonder if we're still bootable?

