-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrub_backup.sh
99 lines (95 loc) · 3.03 KB
/
grub_backup.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
#!/bin/bash
# Check if a copy of the grub configuration file already exists
if ls /etc/default/ | grep -q "grub.bak"; then
# If the file exists, skip it
echo "A backup of the grub configuration file already exists. Skipping."
else
# If the file does not exist, create a backup
# 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 ]; then
case "$os_name" in
"Red Hat Enterprise Linux" | "CentOS")
# Revert the GRUB configuration for Red Hat or CentOS
cp /etc/default/grub /etc/default/grub.bak &&
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub saved for Red Hat or CentOS"
;;
"Arch Linux")
# Revert the GRUB configuration for Red Hat or CentOS
cp /etc/default/grub /etc/default/grub.bak &&
grub-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub saved for Arch"
;;
"Ubuntu")
# Revert the GRUB configuration for Ubuntu
cp /etc/default/grub /etc/default/grub.bak &&
update-grub 2> /dev/null
echo "grub saved for Ubuntu"
;;
"Debian")
# Revert the GRUB configuration for Debian
cp /etc/default/grub /etc/default/grub.bak &&
update-grub 2> /dev/null
echo "grub saved for Debian"
;;
"Fedora Linux")
# Revert the GRUB configuration for Fedora
cp /etc/default/grub /etc/default/grub.bak &&
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub saved for Fedora"
;;
"openSUSE")
# Revert the GRUB configuration for openSUSE
cp /etc/default/grub /etc/default/grub.bak &&
grub2-mkconfig -o "$grub_cfg" 2> /dev/null
echo "grub saved for openSUSE"
;;
# "Custom_linux_distro")
# Revert the GRUB configuration for Debian
# cp /etc/default/grub.bak /etc/default/grub &&
# update-grub 2> /dev/null
# echo "grub saved for Debian"
# ;;
# "Custom_linux_distro")
# # Revert the GRUB configuration for Red Hat or CentOS
# cp /etc/default/grub.bak /etc/default/grub &&
# grub-mkconfig -o "$grub_cfg" 2> /dev/null
# echo "grub saved for Red Hat or CentOS"
# ;;
*)
echo "Backed up the grub configuration file to /etc/default/grub.bak"
;;
esac
fi
fi