-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuninstall.sh
executable file
·66 lines (51 loc) · 1.53 KB
/
uninstall.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
#!/usr/bin/env bash
# 'use strict'
# see https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Euo pipefail # no -e as we may try to remove non-existent .old file
# file locator
SCRIPT_DIR=$(dirname "$(realpath -e "${BASH_SOURCE[0]:-$0}")")
source "$SCRIPT_DIR/lib/common.sh"
if [ "$#" -lt 1 ]; then
echo "Usage: ./uninstall.sh {{kernel_version}}"
echo
echo "Kernels installed:"
"$SCRIPT_DIR/where.sh"
exit 1
fi
KERNVER="$1"
KERNPKG="$(dpkg -S "/boot/vmlinuz-$KERNVER" 2> /dev/null | perl -pe 's/: .*//' || true)"
if [ -n "$KERNPKG" ]; then
echo "Kernel $KERNVER belongs to package '$KERNPKG'."
echo "Please remove it with your package manager."
exit 1
fi
echo "You are about to remove kernel: $KERNVER"
read -p "Are you sure? " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
if [ ! -f "/boot/vmlinuz-$KERNVER" ]; then
echo "$KERNVER does not exist."
exit 1
fi
echo
echo "Uninstalling kernel $KERNVER"
sudo rm "/boot/config-$KERNVER"
sudo rm "/boot/initrd.img-$KERNVER"
sudo rm "/boot/System.map-$KERNVER"
sudo rm "/boot/vmlinuz-$KERNVER"
sudo rm "/var/lib/initramfs-tools/$KERNVER"
sudo rm -rf "/lib/modules/$KERNVER/"
sudo rm -rf "/usr/lib/linux-tools/$KERNVER/"
sudo rm "/boot/config-$KERNVER.old"
sudo rm "/boot/initrd.img-$KERNVER.old"
sudo rm "/boot/System.map-$KERNVER.old"
sudo rm "/boot/vmlinuz-$KERNVER.old"
sudo rm "/var/lib/initramfs-tools/$KERNVER.old"
read -p "Do you need to update grub? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo update-grub
fi
echo "Kernel ($KERNVER) uninstalled, please reboot"