forked from adam8157/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel-clear
executable file
·57 lines (48 loc) · 1.21 KB
/
kernel-clear
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
#!/bin/bash
CURRENT="`uname -r | awk -F"-" '{print $1"-"$2}'`"
HEADERS=""
IMAGES=""
ARCH="amd64"
for HEADER in `dpkg --get-selections | grep ^linux-image \
| grep -v "linux-image-${ARCH}" | awk -F "-" '{print $3"-"$4}'`
do
NEWER=$(echo -e "${CURRENT}\n${HEADER}" |sort -Vr |head -n 1)
if [ "$CURRENT" != "$NEWER" ]
then
echo "Running kernel is not the newest. $CURRENT < $HEADER"
exit 1
else
if [ "$CURRENT" != "$HEADER" ]
then
IMAGE="`dpkg --get-selections | grep ^linux-image \
| grep "${HEADER}" | awk '{print $1}'`"
IMAGES="${IMAGES} $IMAGE"
HEADERS="${HEADERS} linux-headers-${HEADER}-common"
HEADERS="${HEADERS} linux-headers-${HEADER}-${ARCH}"
MODULES="${MODULES} /lib/modules/${HEADER}-${ARCH}"
fi
fi
done
PACKAGES="$IMAGES $HEADERS"
if [ -z "$IMAGES" ]
then
echo "No older kernel or headers package."
exit 1
fi
echo
echo ------------------------------------
echo "$IMAGES $HEADERS $MODULES"
echo ------------------------------------
echo
read -p "Really wanna purge these packages or directories? [y/N] " REPLY
case $REPLY in
y | Y)
for PACKAGE in $PACKAGES
do
sudo apt-get purge -y $PACKAGE
done
sudo rm -rvf $MODULES;;
*)
echo "The operation is cancelled.";;
esac
exit 0