-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathinstall_theme.sh
More file actions
executable file
·133 lines (115 loc) · 4.64 KB
/
Copy pathinstall_theme.sh
File metadata and controls
executable file
·133 lines (115 loc) · 4.64 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# requires to be run as root, unless the user has access to the theme folder
if [[ `id -u` -ne 0 ]] ; then
echo "Must be run as root!"
exit
fi
# this should be the directory of the clones repo
SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# I accidentally deleted the above line once and it copied / into the theme folder, so lets prevent this
if [[ -z $SCRIPT_DIR ]] ; then echo "Something didn't work, exiting"; exit; fi
# check if the grub folder is called grub/ or grub2/
if [ -d /boot/grub ] ; then
grub_path="/boot/grub"
grub_prefix="grub"
elif [ -d /boot/grub2 ] ; then
grub_path="/boot/grub2"
grub_prefix="grub2"
else
echo "Can't find a /boot/grub or /boot/grub2 folder. Exiting."
exit
fi
theme_path="$grub_path/themes/minegrub-world-selection"
## Prompts
read -p "[?] Copy/Update the theme to '$theme_path'? [Y/n] " -e copy_theme
if [[ "$copy_theme" =~ y|Y || -z "$copy_theme" ]]; then
echo "[INFO] => Copying the theme files to boot partition:"
# copy recursive, update, verbose
mkdir -p "$theme_path"
cd $SCRIPT_DIR && cp -ruv ./minegrub-world-selection "$grub_path/themes/" | awk '$0 !~ /skipped/ { print "\t"$0 }'
else
echo "[INFO] [Skipping] Copying the theme files to boot partition"
fi
need_run_mkconfig=false
echo
read -p "[?] Apply patch to be able to set the grub-consoles background with GRUB_BACKGROUND? [y/N] " -e apply_patch_background
if [[ "$apply_patch_background" =~ y|Y ]]; then
need_run_mkconfig=true
echo "[INFO] Editing /etc/grub.d/00_header"
# Backing up that file, just in case
cp --no-clobber /etc/grub.d/00_header ./00_header.bak
# Patching that one line in 00_header
sed --in-place -E 's/(.*)elif(.*"x\$GRUB_BACKGROUND" != x ] && [ -f "\$GRUB_BACKGROUND" ].*)/\1fi; if\2/' /etc/grub.d/00_header \
&& bg_patch_applied=true
# change grub configuration
echo "[INFO] Editing /etc/default/grub"
sed -i "/^GRUB_BACKGROUND=/d" /etc/default/grub
echo -e "GRUB_BACKGROUND=$theme_path/dirt.png" >> /etc/default/grub
else
echo "[INFO] [Skipping] Editing grub drop-in-config file."
echo "[INFO] Removing 'GRUB_BACKGROUND' from /etc/default/grub"
sed -i "/^GRUB_BACKGROUND=/d" /etc/default/grub
fi
echo
read -p "[?] Apply patch to show icon for the UEFI entry [y/N] " -e apply_patch_uefi
if [[ "$apply_patch_uefi" =~ y|Y ]]; then
need_run_mkconfig=true
echo "[INFO] Editing '/etc/grub.d/30_uefi-firmware'"
# Backing up that file, just in case
cp --no-clobber /etc/grub.d/30_uefi-firmware ./30_uefi-firmware.bak
# sed'ing that one line
sed --in-place -E '/--class uefi/!s#(menuentry '\''\$LABEL'\'')(.*)$#\1 --class uefi \2#' /etc/grub.d/30_uefi-firmware
else
echo "[INFO] [Skipping] Editing grub drop-in config-file"
fi
echo
read -p "[?] Apply patch to show icons for 'Advanced options' entry [y/N] " -e apply_patch
if [[ "$apply_patch" =~ y|Y ]]; then
need_run_mkconfig=true
echo "[INFO] Editing '/etc/grub.d/10_linux'"
# Backing up that file, just in case
cp --no-clobber /etc/grub.d/10_linux ./10_linux.bak
# sed'ing that one line
sed --in-place -E '/--class submenu/!s#(gettext_printf "Advanced options for %s" "\$\{OS\}" \| grub_quote\)'\'' )\s*(.*)$#\1 --class submenu \2#' /etc/grub.d/10_linux
else
echo "[INFO] [Skipping] Editing grub drop-in config-file"
fi
if [ ! -d "$theme_path" ]; then
echo "[WARN] The theme wasn't installed. Try to run the script again. Exiting."
exit 0
fi
echo
sleep 0.5 # Just for fun
echo "[INFO] Setting theme in /etc/default/grub"
sed -i "/^GRUB_TIMEOUT_STYLE=/d" /etc/default/grub
sed -i "/^GRUB_THEME=/d" /etc/default/grub
echo -e "GRUB_TIMEOUT_STYLE=menu" >> /etc/default/grub
echo -e "GRUB_THEME=$theme_path/theme.txt" >> /etc/default/grub
sleep 1
echo
echo "======= Done! ======="
echo
echo "| Make sure these lines were added to /etc/default/grub:"
if [[ "$bg_patch_applied" == "true" ]] ; then
echo -e "| GRUB_BACKGROUND=$theme_path/dirt.png"
fi
echo -e "| GRUB_THEME=$theme_path/theme.txt"
# Optionally run grub-mkconfig
mkconfig_cmd="$grub_prefix-mkconfig"
if [[ "$need_run_mkconfig" == "true" ]]; then
echo "| You need to run the following command:"
echo "| > '$mkconfig_cmd -o $grub_path/grub.cfg'"
echo
read -p "[?] Run $mkconfig_cmd now? [Y/n] " -e mkconfig
if [[ "$mkconfig" =~ y|Y || -z "$mkconfig" ]]; then
$mkconfig_cmd -o "$grub_path/grub.cfg"
fi
else
echo "| and then run:"
echo "| > '$mkconfig_cmd -o $grub_path/grub.cfg'"
echo
read -p "[?] Run $mkconfig_cmd now? [y/N] " -e mkconfig
if [[ "$mkconfig" =~ y|Y ]]; then
$mkconfig_cmd -o "$grub_path/grub.cfg"
fi
fi