Created
December 15, 2014 08:32
-
-
Save vehrka/ce94fe69e774c5d2c8a2 to your computer and use it in GitHub Desktop.
Removing old kernels from Ubuntu
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
#!/bin/bash | |
if [ `id -u` -ne 0 ]; then | |
echo "Please run as root" | |
exit | |
else | |
kernelsv=`ls /boot | grep vmlinuz | cut -d'-' -f2,3` | |
nkernv=0 | |
out='' | |
for kernv in ${kernelsv[@]} | |
do | |
out="$out FALSE $kernv" | |
nkernv=$(( $nkernv + 1 )) | |
done | |
height=$(( 100 + $nkernv * 30 )) | |
remkern=`zenity --list --checklist --separator=" " --height $height --column "Remove" --column "Kernel version" $out` | |
flag=0 | |
for rmker in ${remkern[@]} | |
do | |
lista=`dpkg -l | grep ^ii | grep $rmker | awk -F' ' '{ print $2 }'` | |
zenity --question --text "Remove this packages?:\n\n$lista" | |
if [[ $? = 0 ]]; then | |
flag=1 | |
echo "Removing $rmker" | |
lista=`dpkg -l | grep ^ii | grep $rmker | awk -F' ' '{ printf ("%s ", $2) }'` | |
apt-get --purge --yes remove $lista | |
fi | |
done | |
if [[ $flag = 1 ]]; then | |
update-grub | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment