forked from vinceliuice/grub2-themes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·444 lines (394 loc) · 12.8 KB
/
install.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#!/bin/bash
# Grub2 Themes
set -o errexit
[ GLOBAL::CONF ]
{
readonly ROOT_UID=0
readonly Project_Name="GRUB2::THEMES"
readonly MAX_DELAY=20 # max delay for user to enter root password
tui_root_login=
THEME_DIR="/usr/share/grub/themes"
REO_DIR="$(cd $(dirname $0) && pwd)"
}
#COLORS
CDEF=" \033[0m" # default color
CCIN=" \033[0;36m" # info color
CGSC=" \033[0;32m" # success color
CRER=" \033[0;31m" # error color
CWAR=" \033[0;33m" # waring color
b_CDEF=" \033[1;37m" # bold default color
b_CCIN=" \033[1;36m" # bold info color
b_CGSC=" \033[1;32m" # bold success color
b_CRER=" \033[1;31m" # bold error color
b_CWAR=" \033[1;33m" # bold warning color
# echo like ... with flag type and display message colors
prompt () {
case ${1} in
"-s"|"--success")
echo -e "${b_CGSC}${@/-s/}${CDEF}";; # print success message
"-e"|"--error")
echo -e "${b_CRER}${@/-e/}${CDEF}";; # print error message
"-w"|"--warning")
echo -e "${b_CWAR}${@/-w/}${CDEF}";; # print warning message
"-i"|"--info")
echo -e "${b_CCIN}${@/-i/}${CDEF}";; # print info message
*)
echo -e "$@"
;;
esac
}
# Check command avalibility
function has_command() {
command -v $1 > /dev/null
}
usage() {
printf "%s\n" "Usage: ${0##*/} [OPTIONS...]"
printf "\n%s\n" "OPTIONS:"
printf " %-25s%s\n" "-b, --boot" "install grub theme into /boot/grub/themes"
printf " %-25s%s\n" "-l, --slaze" "slaze grub theme"
printf " %-25s%s\n" "-s, --stylish" "stylish grub theme"
printf " %-25s%s\n" "-t, --tela" "tela grub theme"
printf " %-25s%s\n" "-v, --vimix" "vimix grub theme"
printf " %-25s%s\n" "-c, --cyberlight" "Cyber Punk light grub theme - only on 1080p ultrawide"
printf " %-25s%s\n" "-d, --cyberdark" "Cyber Punk dark grub theme - only on 1080p ultrawide"
printf " %-25s%s\n" "-w, --white" "Install white icon version"
printf " %-25s%s\n" "-u, --ultrawide" "Install 2560x1080 background image - not available for slaze grub theme"
printf " %-25s%s\n" "-2, --2k" "Install 2k(2560x1440) background image"
printf " %-25s%s\n" "-4, --4k" "Install 4k(3840x2160) background image"
printf " %-25s%s\n" "-r, --remove" "Remove theme (must add theme name option)"
printf " %-25s%s\n" "-h, --help" "Show this help"
}
install() {
if [[ ${theme} == 'slaze' ]]; then
local name="Slaze"
elif [[ ${theme} == 'stylish' ]]; then
local name="Stylish"
elif [[ ${theme} == 'tela' ]]; then
local name="Tela"
elif [[ ${theme} == 'vimix' ]]; then
local name="Vimix"
elif [[ ${theme} == 'cyberlight' ]]; then
local name="CyberLight"
elif [[ ${theme} == 'cyberdark' ]]; then
local name="CyberDark"
else
prompt -i "\n Run ./install.sh -h for help or install dialog"
install_dialog
prompt -i "\n Run ./install.sh again!"
exit 0
fi
if [[ ${screen} == '2k' ]]; then
local screen="2k"
elif [[ ${screen} == '4k' ]]; then
local screen="4k"
elif [[ ${screen} == '1080p_21:9' ]]; then
local screen="1080p_21:9"
else
local screen="1080p"
fi
if [[ ${screen} == '1080p_21:9' && ${name} == 'Slaze' ]]; then
prompt -e "ultrawide 1080p does not support Slaze theme"
exit 1
fi
if [[ ${name} =~ ^(CyberLight|CyberDark)$ && ${screen} != *'1080'* ]]; then
prompt -e "$name grub theme is only available for ultrawide 1080p"
exit 1
fi
if [[ ${name} =~ ^(CyberLight|CyberDark) || ${screen} == '1080p_21:9' ]]; then
local extension='png'
else
local extension='jpg'
fi
#check if is a light theme
if [[ ${name} =~ ^(CyberLight)$ ]]; then
local themeconfig="${screen}-light"
local asset="light"
else
local themeconfig="${screen}"
local asset="dark"
fi
if [[ ${icon} == 'white' ]]; then
local icon="white"
else
local icon="color"
fi
# Checking for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then
clear
# Create themes directory if not exists
echo -e "\n Checking for the existence of themes directory..."
[[ -d "${THEME_DIR}/${name}" ]] && rm -rf "${THEME_DIR}/${name}"
mkdir -p "${THEME_DIR}/${name}"
# Copy theme
prompt -i "\n Installing ${name} ${icon}_icon ${asset}_profile ${screen} theme..."
cp -a "${REO_DIR}/common/"* "${THEME_DIR}/${name}"
cp -a "${REO_DIR}/config/theme-${themeconfig}.txt" "${THEME_DIR}/${name}/theme.txt"
cp -a "${REO_DIR}/backgrounds/${screen}/background-${theme}.${extension}" "${THEME_DIR}/${name}/background.${extension}"
cp -a "${REO_DIR}/assets/icons-${icon}/icons-${screen}" "${THEME_DIR}/${name}/icons"
cp -a "${REO_DIR}/assets/assets-${asset}/select-${screen}/"*.png "${THEME_DIR}/${name}"
# Edit themeConfig to correct background file extension
sed -i "s/background\.ext/background.${extension}/g" "${THEME_DIR}/${name}/theme.txt"
# dirty edit themeConfig to correct menu width, when in cyberpunk theme
if [[ $screen == "1080p" && ${name} =~ ^(CyberLight|CyberDark) ]]; then
prompt -w "applying quick fix for cyberpunk theme dimension on 1080p"
sed -i "0,/width = [[:digit:]]\+/{s//width = 35/}" "${THEME_DIR}/${name}/theme.txt"
sed -i "0,/left = [[:digit:]]\+/{s//left = 25/}" "${THEME_DIR}/${name}/theme.txt"
fi
# Set theme
prompt -i "\n Setting ${name} as default..."
# Backup grub config
cp -an /etc/default/grub /etc/default/grub.bak
grep "GRUB_THEME=" /etc/default/grub 2>&1 >/dev/null && sed -i '/GRUB_THEME=/d' /etc/default/grub
grep "GRUB_GFXMODE=" /etc/default/grub 2>&1 >/dev/null && sed -i '/GRUB_GFXMODE=/d' /etc/default/grub
# Edit grub config
echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub
# Make sure set the right resolution for grub
if [[ ${screen} == '1080p' ]]; then
echo "GRUB_GFXMODE=1920x1080,auto" >> /etc/default/grub
elif [[ ${screen} == '1080p_21:9' ]]; then
echo "GRUB_GFXMODE=2560x1080,auto" >> /etc/default/grub
elif [[ ${screen} == '4k' ]]; then
echo "GRUB_GFXMODE=3840x2160,auto" >> /etc/default/grub
elif [[ ${screen} == '2k' ]]; then
echo "GRUB_GFXMODE=2560x1440,auto" >> /etc/default/grub
fi
# Update grub config
prompt -i "\n Updating grub config...\n"
updating_grub
else
# Error message
prompt -e "\n [ Error! ] -> Run me as root! "
# persisted execution of the script as root
if [[ -n ${tui_root_login} ]] ; then
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S <<< ${tui_root_login} $0 ${ORIGINAL_ARGUMENTS}
fi
else
read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s
[[ -n "$REPLY" ]] && {
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S <<< $REPLY $0 ${ORIGINAL_ARGUMENTS}
fi
} || {
operation_canceled
}
fi
fi
}
run_dialog() {
if [[ -x /usr/bin/dialog ]]; then
tui_root_login=$(dialog --backtitle ${Project_Name} \
--title "ROOT LOGIN" \
--insecure \
--passwordbox "require root permission" 8 50 \
--output-fd 1 )
[[ -z ${tui_root_login} ]] && exit ${UID}
sudo -S <<< $tui_root_login $0
test $? -eq 0 || {
prompt -e "\n [ Error! ] -> wrong passwords"
exit 1
}
tui=$(dialog --backtitle ${Project_Name} \
--radiolist "Choose your Grub theme : " 15 40 5 \
1 "Vimix Theme" off \
2 "Tela Theme" on \
3 "Stylish Theme" off \
4 "Slaze Theme" off \
5 "Cyber Punk light Theme" off \
6 "Cyber Punk dark Theme" off --output-fd 1 )
case "$tui" in
1) theme="vimix" ;;
2) theme="tela" ;;
3) theme="stylish" ;;
4) theme="slaze" ;;
5) theme="cyberlight" ;;
6) theme="cyberdark" ;;
*) operation_canceled ;;
esac
tui=$(dialog --backtitle ${Project_Name} \
--radiolist "Choose icon style : " 15 40 5 \
1 "white" off \
2 "color" on --output-fd 1 )
case "$tui" in
1) icon="white" ;;
2) icon="color" ;;
*) operation_canceled ;;
esac
tui=$(dialog --backtitle ${Project_Name} \
--radiolist "Choose your Display Resolution : " 15 40 5 \
1 "1080p" on \
2 "1080p ultrawide" off \
3 "2k" off \
4 "4k" off --output-fd 1 )
case "$tui" in
1) screen="1080p" ;;
2) screen="1080p_21:9" ;;
3) screen="2k" ;;
4) screen="4k" ;;
*) operation_canceled ;;
esac
fi
}
operation_canceled() {
clear
prompt -i "\n Operation canceled by user, Bye!"
exit 1
}
updating_grub() {
if has_command update-grub; then
update-grub
elif has_command grub-mkconfig; then
grub-mkconfig -o /boot/grub/grub.cfg
elif has_command zypper; then
grub2-mkconfig -o /boot/grub2/grub.cfg
elif has_command dnf; then
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
fi
# Success message
prompt -s "\n * All done!"
prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' "
}
install_dialog() {
if [ ! "$(which dialog 2> /dev/null)" ]; then
prompt -i "\n 'dialog' needs to be installed for this shell"
if has_command zypper; then
sudo zypper in dialog
elif has_command apt-get; then
sudo apt-get install dialog
elif has_command dnf; then
sudo dnf install -y dialog
elif has_command yum; then
sudo yum install dialog
elif has_command pacman; then
sudo pacman -S --noconfirm dialog
fi
fi
}
remove() {
if [[ ${theme} == 'slaze' ]]; then
local name="Slaze"
elif [[ ${theme} == 'stylish' ]]; then
local name="Stylish"
elif [[ ${theme} == 'tela' ]]; then
local name="Tela"
elif [[ ${theme} == 'vimix' ]]; then
local name="Vimix"
elif [[ ${theme} == 'cyberlight' ]]; then
local name="CyberLight"
elif [[ ${theme} == 'cyberdark' ]]; then
local name="CyberDark"
else
prompt -i "\n Run ./install.sh -h for help!"
exit 0
fi
# Checking for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then
echo -e "\n Checking for the existence of themes directory..."
if [[ -d "${THEME_DIR}/${name}" ]]; then
rm -rf "${THEME_DIR}/${name}"
else
prompt -i "\n ${name} grub theme not exist!"
exit 0
fi
# Backup grub config
if [[ -f /etc/default/grub.bak ]]; then
rm -rf /etc/default/grub && mv /etc/default/grub.bak /etc/default/grub
else
prompt -i "\n grub.bak not exist!"
exit 0
fi
# Update grub config
prompt -i "\n Resetting grub theme...\n"
updating_grub
else
# Error message
prompt -e "\n [ Error! ] -> Run me as root "
# persisted execution of the script as root
read -p "[ trusted ] specify the root password : " -t${MAX_DELAY} -s
[[ -n "$REPLY" ]] && {
if [[ -n "${theme}" ]]; then
sudo -S <<< $REPLY $0 --remove --${theme}
fi
} || {
operation_canceled
}
fi
}
# show terminal user interface for better use
if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ -x /usr/bin/dialog ]] ; then
run_dialog
fi
if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ ! -x /usr/bin/dialog ]] ; then
# Error message
prompt -e "\n [ Error! ] -> Run me as root! "
# persisted execution of the script as root
read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s
[[ -n "$REPLY" ]]&& {
exec sudo -S <<< $REPLY $0
}|| {
operation_canceled
}
fi
while [[ $# -ge 1 ]]; do
ORIGINAL_ARGUMENTS="$ORIGINAL_ARGUMENTS $1"
case "${1}" in
-b|--boot)
THEME_DIR="/boot/grub/themes"
;;
-l|--slaze)
theme='slaze'
;;
-s|--stylish)
theme='stylish'
;;
-t|--tela)
theme='tela'
;;
-v|--vimix)
theme='vimix'
;;
-c|--cyberlight)
theme='cyberlight'
;;
-d|--cyberdark)
theme='cyberdark'
;;
-w|--white)
icon='white'
;;
-c|--color)
icon='color'
;;
-1|--1080p)
screen='1080p'
;;
-2|--2k)
screen='2k'
;;
-4|--4k)
screen='4k'
;;
-u|--ultrawide|--1080p_21:9)
screen='1080p_21:9'
;;
-r|--remove)
remove='true'
;;
-h|--help)
usage
exit 0
;;
*)
prompt -e "\n ERROR: Unrecognized installation option '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
shift
done
if [[ "${remove:-}" != 'true' ]]; then
install
elif [[ "${remove:-}" == 'true' ]]; then
remove
fi
exit 0