-
Notifications
You must be signed in to change notification settings - Fork 0
/
grub_update.sh
87 lines (82 loc) · 2.47 KB
/
grub_update.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
83
84
85
86
87
#!/bin/bash
# Check the contents of the /etc/os-release file
os_name=$(grep "^NAME=" /etc/os-release | cut -d '"' -f 2)
## Linux Definitions.
# Set the location of the GRUB configuration file
case "$os_name" in
"Red Hat Enterprise Linux" | "CentOS")
grub_cfg="/boot/grub2/grub.cfg"
;;
"Arch Linux"| "Manjaro")
grub_cfg="/boot/grub/grub.cfg"
;;
"Ubuntu" | "Debian")
grub_cfg="/boot/grub/grub.cfg"
;;
"Fedora Linux")
grub_cfg="/boot/grub2/grub.cfg"
;;
"openSUSE")
grub_cfg="/boot/grub2/grub.cfg"
;;
# "Custom_linux_distro")
# grub_cfg="/boot/grub2/grub.cfg"
# ;;
# "Custom_linux_distro")
# grub_cfg="/boot/grub/grub.cfg"
# ;;
*)
echo "Unknown Linux distribution: $os_name"
exit 1
;;
esac
# Check if the file exists
if [ -f /etc/default/grub.bak ]; then
case "$os_name" in
"Red Hat Enterprise Linux" | "CentOS")
# Revert the GRUB configuration for Red Hat or CentOS
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub updated for Red Hat or CentOS"
;;
"Arch Linux")
# Revert the GRUB configuration for Red Hat or CentOS
grub-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub updated for Arch"
;;
"Ubuntu")
# Revert the GRUB configuration for Ubuntu
update-grub 2> /dev/null
echo "grub updated for Ubuntu"
;;
"Debian")
# Revert the GRUB configuration for Debian
update-grub 2> /dev/null
echo "grub updated for Debian"
;;
"Fedora Linux")
# Revert the GRUB configuration for Fedora
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub updated for Fedora"
;;
"openSUSE")
# Revert the GRUB configuration for openSUSE
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub updated for openSUSE"
;;
# "Custom_linux_distro")
# Revert the GRUB configuration for Debian
# mv /etc/default/grub.bak /etc/default/grub &&
# update-grub 2> /dev/null
# echo "grub updated for Debian"
# ;;
# "Custom_linux_distro")
# # Revert the GRUB configuration for Red Hat or CentOS
# mv /etc/default/grub.bak /etc/default/grub &&
# grub-mkconfig -o "$grub_cfg" 2> /dev/null
# echo "grub updated for Red Hat or CentOS"
# ;;
*)
echo "Unable to revert grub for unknown Linux distribution: $os_name"
;;
esac
fi