forked from muhasturk/ukupgrade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ukpurge
executable file
·80 lines (64 loc) · 1.85 KB
/
ukpurge
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# @author Caio Oliveira
# @mail [email protected]
# @author Usb Key
# @mail [email protected]
#Follow symlink and cd to right directory
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
cd "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
if [ -f ./uku.cfg ]; then source ./uku.cfg ; else arm=0; fi
lkv=`uname -r`
kernels=($(dpkg --list | grep -E "linux-headers" | grep -v "generic" | awk '{ print $2 }' | cut -d'-' -f3- | sort -uV | head -n -2))
function keepBaseVersion(){
nb=0
base=$(echo "${kernels[0]}" | cut -d'-' -f1)
for kernel in "${kernels[@]}"
do
if [[ $base = $(echo "$kernel" | cut -d'-' -f1) ]]; then ((nb++)) ;fi
done
if [[ $nb > 1 ]]; then unset 'kernels[nb-1]'; fi
}
function remove() {
for kernel in "${kernels[@]}"
do
dpkg --list | awk '{ print $2 }' | grep "$kernel" | xargs sudo apt-get -y purge
done
}
keepBaseVersion
echo
echo "Ubuntu Kernel Purge - by Caio Oliveira"
echo
echo "This script will only keep three versions: the first and the last two, others will be purge"
if [ "$(echo $lkv | grep -o generic | head -1)" = "generic" ]
then lkve="Generic"; nlkv=`echo $lkv | rev | cut -c 9- | rev`
else lkve="LowLatency"; nlkv=`echo $lkv | rev | cut -c 12- | rev`
fi
echo
echo "---Current version:"
echo "Linux Kernel $nlkv $lkve (linux-image-$lkv)"
if [ -z "$kernels" ];
then echo "Nothing to remove!" ;
else
echo
echo "---Versions to remove:"
printf '%s\n' "${kernels[@]}"
echo
if [ $arm = 0 ];
then
read -p "---Do you want to remove the old kernels/headers versions? (Y/n): " -n 1 -t 10 -s rr
case "$rr" in
Y) echo "Yes, remove this now!";
sleep 2;
remove ;;
*) echo "No, thanks!" ;;
esac ;
else remove ;
fi
fi
echo
echo "Thanks for using this script!!!"