-
Notifications
You must be signed in to change notification settings - Fork 1
/
uninstall.sh
executable file
·63 lines (57 loc) · 2.5 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
#!/bin/sh
set -ex
HAS_BLS="$(test -d /boot/loader/entries && echo 1 || echo 0)"
HAS_OSTREE="$(test -d /ostree && echo 1 || echo 0)"
HAS_GRUB1="$(test -f /boot/grub/grub.cfg && echo 1 || echo 0)"
HAS_GRUB2="$(test -f /boot/grub2/grub.cfg && echo 1 || echo 0)"
HAS_SYSTEMD="$(test -f /usr/bin/systemctl && echo 1 || echo 0)"
HAS_NETWORKD="$(systemctl --quiet is-enabled systemd-networkd && echo 1 || echo 0)"
HAS_NM="$(test -f /usr/bin/nmcli && echo 1 || echo 0)"
disable_dracut_iscsi() {
echo "Disabling iSCSI Initiator support in Dracut initramfs"
rm -f /etc/dracut.conf.d/90-iscsi-target-ramdisk.conf
if [ "$HAS_OSTREE" = "1" ]; then
(rpm-ostree initramfs | grep -q "Initramfs regeneration: disabled") || rpm-ostree initramfs --disable
else
# We have just removed the dracut config containing the hostonly options.
# If this uninstall script is being run on the initiator, hostonly mode
# may result in initramfs that dont run on the original target, so to be
# safe we use no-hostonly mode once to ensure working initramfs.
dracut --force --no-hostonly --no-hostonly-cmdline
fi
}
remove_boot_entry() {
echo "Removing iSCSI Target Ramdisk boot menu entry"
if [ "$HAS_BLS" = "1" -a "$HAS_OSTREE" = "0" ]; then
rm -f /boot/loader/entries/iscsi-target-ramdisk.conf
else
rm -f /etc/grub.d/42_iscsi-target-ramdisk
if [ "$HAS_GRUB1" = "1" ]; then
grub-mkconfig -o /boot/grub/grub.cfg
elif [ "$HAS_GRUB2" = "1" ]; then
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
fi
}
preserve_kernel_cmdline() {
if [ -f /etc/kernel/cmdline ]; then
echo "Custom /etc/kernel/cmdline detected, review manually and remove to go back to default cmdline detection (e.g. /etc/default/grub:GRUB_CMDLINE_LINUX)."
fi
}
remove_bootif_unmanaged() {
if [ "$HAS_NETWORKD" = "1" ]; then
echo "Removing setting for iSCSI BOOTIF as unmanaged in systemd-networkd"
rm -f /etc/systemd/network/00-bootnet-unmanaged.network
elif [ "$HAS_NM" = "1" -a "$HAS_SYSTEMD" = "1" ]; then
echo "Removing script to set iSCSI BOOTIF as unmanaged in NetworkManager..."
systemctl disable bootnet-nm-unmanaged
rm -f /etc/systemd/system/bootnet-nm-unmanaged.service
fi
}
disable_dracut_iscsi
remove_boot_entry
preserve_kernel_cmdline
remove_bootif_unmanaged
rm -f /boot/iscsi-target-ramdisk-kernel.bin
rm -f /boot/iscsi-target-ramdisk-initrd.bin
rm -f /usr/local/sbin/uninstall-iscsi-target-ramdisk.sh