-
Notifications
You must be signed in to change notification settings - Fork 0
/
kremove.sh
executable file
·83 lines (68 loc) · 1.79 KB
/
kremove.sh
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
81
82
#!/bin/sh
# program to remove a kernel
# Peter Hyman, [email protected]
# No warranties, and free to use and copy
# Prefixes
BOOT="/boot"
LIB="/lib/modules"
USDIR="/usr/src"
CKV=`uname -r`
ISREMOVED=0
# root test
if [ $UID -ne "0" ] ; then
echo "Only root can do...Exit"
exit 1
fi
# usage test
if [ $# -ne "1" ] ; then
echo "Usage: \"$0 kernel_version\"...Exit"
exit 1
fi
# current kernel test
if [ "$CKV" == "$1" ] ; then
echo "Cannot remove current kernel...Exit"
exit 1
fi
# modules test
if [ ! -e "$LIB/$1" ] ; then
echo "Cannot find module directory. Is kernel $1 installed? Exiting..."
exit 1
fi
# individual file tests
echo "Removing kernel $1 boot directory files..."
if [ ! -e "$BOOT/initrd-$1.gz" ] ; then
echo "Can't find kernel initrd-$1.gz to remove...Continuing"
else
rm -v $BOOT/initrd-$1.gz
ISREMOVED=1
fi
if [ ! -e "$BOOT/vmlinuz-$1" ] ; then
echo "Can't find kernel vmlinuz-$1 to remove...Continuing"
else
rm -v $BOOT/vmlinuz-$1
[ $ISREMOVED -eq 0 ] && ISREMOVED=1
fi
if [ ! -e "$BOOT/System.map-$1" ] ; then
echo "Can't find kernel System.map-$1 to remove...Continuing"
else
rm -v $BOOT/System.map-$1
[ $ISREMOVED -eq 0 ] && ISREMOVED=1
fi
if [ ! -e "$BOOT/config-$1" ] ; then
echo "Can't find kernel config-$1 to remove...Continuing"
else
rm -v $BOOT/config-$1
[ $ISREMOVED -eq 0 ] && ISREMOVED=1
fi
[ $ISREMOVED -eq 0 ] && echo "Odd that no files removed from $BOOT directory"
# Already tested for existence of lib directory
echo "Removing module directory $LIB/$1"
rm -fr $LIB/$1
# Remove kernel source directory if present
if [ ! -e "$USDIR/linux-$1" ] ; then
echo "Can't find $USDIR/linux-$1 source directory...Continuing"
else
echo "Removing kernel $1 source directory or link..."
rm -fr $USDIR/linux-$1
fi
echo "Kernel $1 removed. EFI directories, if any, not touched."