-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrub_revert.sh
111 lines (105 loc) · 3.2 KB
/
grub_revert.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/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
echo "Do you want to revert grub for $os_name? [y/n]"
read answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
case "$os_name" in
"Red Hat Enterprise Linux" | "CentOS")
# Revert the GRUB configuration for Red Hat or CentOS
mv /etc/default/grub.bak /etc/default/grub &&
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub reverted for Red Hat or CentOS"
;;
"Arch Linux")
# 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 reverted for Arch"
;;
"Ubuntu")
# Revert the GRUB configuration for Ubuntu
mv /etc/default/grub.bak /etc/default/grub &&
update-grub 2> /dev/null
echo "grub reverted for Ubuntu"
;;
"Debian")
# Revert the GRUB configuration for Debian
mv /etc/default/grub.bak /etc/default/grub &&
update-grub 2> /dev/null
echo "grub reverted for Debian"
;;
"Fedora Linux")
# Revert the GRUB configuration for Fedora
mv /etc/default/grub.bak /etc/default/grub &&
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub reverted for Fedora"
;;
"openSUSE")
# Revert the GRUB configuration for openSUSE
mv /etc/default/grub.bak /etc/default/grub &&
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub reverted 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 reverted 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 reverted for Red Hat or CentOS"
# ;;
*)
echo "Unable to revert grub for unknown Linux distribution: $os_name"
;;
esac
read -p "Do you want to reboot? [y/n] " answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
# code to execute if the answer is "yes"
echo "rebooting...."
sleep 5s
reboot
else
# code to execute if the answer is "no"
echo "Exiting script."
sleep 1s
clear
exit
fi
fi
fi