Last active
December 1, 2016 09:19
-
-
Save mhogerheijde/a3505cb20e9481445175114b46f4174b to your computer and use it in GitHub Desktop.
Prune boot linux packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file can/should be sourced (add "source prune-boot.zsh" to your ~/.zshrc) | |
confirm () { | |
# call with a prompt string or use a default | |
echo -n "${1:-Are you sure?} [y/N] " | |
read response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
true | |
;; | |
*) | |
false | |
;; | |
esac | |
} | |
prune-boot() { | |
CURRENT_VERSION=`uname -r | cut -f1,2 -d"-"` | |
echo -e "Current kernel version: \033[1m$CURRENT_VERSION\033[0m" | |
TO_PRUNE=`dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e $CURRENT_VERSION` | |
echo "List of installed kernel packages:" | |
echo "$TO_PRUNE" | |
echo | |
confirm "Do you want to delete these packages?" \ | |
&& sudo mount -o remount,rw /boot \ | |
&& echo $TO_PRUNE | xargs sudo apt-get -y purge \ | |
&& sudo mount -o remount,ro /boot | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment