forked from anoopmsivadas/Cyberpunk-GRUB-Theme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·103 lines (83 loc) · 3.27 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
#!/bin/bash
# Modified version from Tela Theme [https://github.com/vinceliuice/grub2-themes]
# Grub2 Theme
ROOT_UID=0
THEME_DIR="/usr/share/grub/themes"
THEME_NAME=Cyberpunk
MAX_DELAY=20 # max delay for user to enter root password
#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
}
# Welcome message
prompt -s "\n\t************************\n\t* ${THEME_NAME} - Grub2 Theme *\n\t************************"
# Check command avalibility
function has_command() {
command -v $1 > /dev/null
}
prompt -w "\nChecking for root access...\n"
# Checking for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then
# Create themes directory if not exists
prompt -i "\nChecking for the existence of themes directory...\n"
[[ -d ${THEME_DIR}/${THEME_NAME} ]] && rm -rf ${THEME_DIR}/${THEME_NAME}
mkdir -p "${THEME_DIR}/${THEME_NAME}"
# Copy theme
prompt -i "\nInstalling ${THEME_NAME} theme...\n"
cp -a ${THEME_NAME}/* ${THEME_DIR}/${THEME_NAME}
# Set theme
prompt -i "\nSetting ${THEME_NAME} as default...\n"
# 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
echo "GRUB_THEME=\"${THEME_DIR}/${THEME_NAME}/theme.txt\"" >> /etc/default/grub
# Update grub config
echo -e "Updating grub config..."
if has_command update-grub; then
update-grub
elif has_command grub-mkconfig; then
grub-mkconfig -o /boot/grub/grub.cfg
elif has_command grub2-mkconfig; then
if 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
fi
# Success message
prompt -s "\n\t ***************\n\t * All done! *\n\t ***************\n"
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" ]] && {
sudo -S <<< $REPLY $0
} || {
prompt "\n Operation canceled Bye"
exit 1
}
fi