grub2-themes/install.sh

242 lines
7.0 KiB
Bash
Raw Normal View History

2019-05-31 09:15:27 +02:00
#!/bin/bash
2019-06-08 04:49:28 +02:00
# Grub2 Dark Theme
2019-05-31 09:15:27 +02:00
ROOT_UID=0
THEME_DIR="/boot/grub/themes"
THEME_DIR_2="/boot/grub2/themes"
2019-08-30 03:55:07 +02:00
REO_DIR="$(cd $(dirname $0) && pwd)"
2019-05-31 09:15:27 +02:00
2019-06-08 04:49:28 +02:00
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
2019-06-08 04:49:28 +02:00
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
}
2019-05-31 09:15:27 +02:00
# Check command avalibility
function has_command() {
command -v $1 > /dev/null
}
usage() {
printf "%s\n" "Usage: ${0##*/} [OPTIONS...]"
2019-05-31 09:15:27 +02:00
printf "\n%s\n" "OPTIONS:"
2019-05-31 09:51:14 +02:00
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"
2019-05-31 09:15:27 +02:00
printf " %-25s%s\n" "-h, --help" "Show this help"
}
install() {
2019-05-31 09:51:14 +02:00
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"
else
2019-06-08 04:49:28 +02:00
prompt -i "\n Run sudo ./install.sh again! or run ./install.sh -h for help"
2019-05-31 09:51:14 +02:00
exit 0
2019-06-08 04:49:28 +02:00
fi
2019-05-31 09:51:14 +02:00
# Checking for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then
# Create themes directory if not exists
echo -e "\n Checking for the existence of themes directory..."
2019-06-08 04:49:28 +02:00
2019-08-30 03:55:07 +02:00
[[ -d "${THEME_DIR}/${name}" ]] && rm -rf "${THEME_DIR}/${name}"
[[ -d "${THEME_DIR_2}/${name}" ]] && rm -rf "${THEME_DIR_2}/${name}"
[[ -d /boot/grub ]] && mkdir -p "${THEME_DIR}/${name}"
[[ -d /boot/grub2 ]] && mkdir -p "${THEME_DIR_2}/${name}"
2019-05-31 09:51:14 +02:00
# Copy theme
2019-06-08 04:49:28 +02:00
prompt -i "\n Installing ${name} theme..."
2019-05-31 09:51:14 +02:00
if [ -d /boot/grub ]; then
2019-08-30 03:55:07 +02:00
cp -a "${REO_DIR}/common/"* "${THEME_DIR}/${name}"
cp -a "${REO_DIR}/backgrounds/background-${theme}.jpg" "${THEME_DIR}/${name}/background.jpg"
2019-05-31 09:51:14 +02:00
if [ ${theme} == 'tela' ]; then
2019-08-30 03:55:07 +02:00
cp -a "${REO_DIR}/assets/assets-tela/icons" "${THEME_DIR}/${name}"
cp -a "${REO_DIR}/assets/assets-tela/select/"*.png "${THEME_DIR}/${name}"
2019-05-31 09:51:14 +02:00
else
2019-08-30 03:55:07 +02:00
cp -a "${REO_DIR}/assets/assets-white/icons" "${THEME_DIR}/${name}"
cp -a "${REO_DIR}/assets/assets-white/select/"*.png "${THEME_DIR}/${name}"
2019-05-31 09:51:14 +02:00
fi
fi
2019-05-31 09:15:27 +02:00
2019-05-31 09:51:14 +02:00
if [ -d /boot/grub2 ]; then
2019-08-30 03:55:07 +02:00
cp -a "${REO_DIR}/common/"* "${THEME_DIR_2}/${name}"
cp -a "${REO_DIR}/backgrounds/background-${theme}.jpg" "${THEME_DIR_2}/${name}/background.jpg"
2019-05-31 09:51:14 +02:00
if [ ${theme} == 'tela' ]; then
2019-08-30 03:55:07 +02:00
cp -a "${REO_DIR}/assets/assets-tela/icons" "${THEME_DIR_2}/${name}"
cp -a "${REO_DIR}/assets/assets-tela/select/"*.png "${THEME_DIR_2}/${name}"
2019-05-31 09:51:14 +02:00
else
2019-08-30 03:55:07 +02:00
cp -a "${REO_DIR}/assets/assets-white/icons" "${THEME_DIR_2}/${name}"
cp -a "${REO_DIR}/assets/assets-white/select/*".png "${THEME_DIR_2}/${name}"
2019-05-31 09:51:14 +02:00
fi
2019-05-31 09:15:27 +02:00
fi
2019-05-31 09:51:14 +02:00
# Set theme
2019-06-08 04:49:28 +02:00
prompt -i "\n Setting ${name} as default..."
2019-05-31 09:51:14 +02:00
grep "GRUB_THEME=" /etc/default/grub 2>&1 >/dev/null && sed -i '/GRUB_THEME=/d' /etc/default/grub
2019-08-30 03:55:07 +02:00
# Backup grub config
cp -an /etc/default/grub /etc/default/grub.bak
# Edit grub config
2019-05-31 09:51:14 +02:00
[[ -d /boot/grub ]] && echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub
[[ -d /boot/grub2 ]] && echo "GRUB_THEME=\"${THEME_DIR_2}/${name}/theme.txt\"" >> /etc/default/grub
# Update grub config
2019-06-08 04:49:28 +02:00
prompt -i "\n Updating grub config..."
2019-05-31 09:51:14 +02:00
if has_command update-grub; then
2019-06-08 04:49:28 +02:00
update-grub
2019-05-31 09:51:14 +02:00
elif has_command grub-mkconfig; then
grub-mkconfig -o /boot/grub/grub.cfg
elif has_command grub2-mkconfig; then
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
fi
2019-05-31 09:15:27 +02:00
2019-05-31 09:51:14 +02:00
# Success message
2019-06-09 02:12:47 +02:00
prompt -s "\n * All done!"
prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' "
2019-05-31 09:15:27 +02:00
2019-05-31 09:51:14 +02:00
else
2019-05-31 09:15:27 +02:00
# Error message
2019-08-30 03:55:07 +02:00
prompt -e "\n [ Error! ] -> Run me as root "
2019-06-08 04:49:28 +02:00
# 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 --${theme}
fi
}|| {
2019-06-08 04:49:28 +02:00
prompt "\n Operation canceled Bye"
exit 1
}
2019-05-31 09:51:14 +02:00
fi
2019-05-31 09:15:27 +02:00
}
2019-06-08 04:49:28 +02:00
run_dialog() {
if [[ -x /usr/bin/dialog ]]; then
2019-06-28 03:53:50 +02:00
tui=$(dialog --backtitle "GRUB2 THEMES" \
2019-06-08 04:49:28 +02:00
--radiolist "Choose your Grub theme : " 15 40 5 \
2019-06-09 02:12:47 +02:00
1 "Vimix Theme" off \
2 "Tela Theme" on \
3 "Stylish Theme" off \
4 "Slaze Theme" off --output-fd 1 )
2019-06-08 04:49:28 +02:00
case "$tui" in
2019-06-09 02:12:47 +02:00
1) theme="vimix" ;;
2) theme="tela" ;;
3) theme="stylish" ;;
4) theme="slaze" ;;
2019-06-08 04:49:28 +02:00
*) prompt "Canceled" ;;
esac
fi
}
install_dialog() {
if [ ! "$(which dialog 2> /dev/null)" ]; then
2019-06-08 14:43:35 +02:00
prompt -i "\n 'dialog' needs to be installed for this shell"
2019-06-08 04:49:28 +02:00
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 dialog
elif has_command yum; then
sudo yum install dialog
elif has_command pacman; then
sudo pacman -S --noconfirm dialog
fi
fi
}
# show terminal user interface for better use
if [[ $# -lt 1 ]] && [[ $UID -eq $ROOT_UID ]]; then
run_dialog
fi
if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]]; then
2019-06-08 04:54:13 +02:00
# Error message
2019-08-30 03:55:07 +02:00
prompt -e "\n [ Error! ] -> Run me as root "
2019-06-08 04:54:13 +02:00
# persisted execution of the script as root
read -p "[ trusted ] specify the root password : " -t${MAX_DELAY} -s
[[ -n "$REPLY" ]]&& {
2019-06-08 14:43:35 +02:00
exec sudo -S <<< $REPLY $0
2019-06-08 04:54:13 +02:00
}|| {
prompt "\n Operation canceled Bye"
exit 1
}
2019-06-08 04:49:28 +02:00
fi
while [[ $# -ge 1 ]]; do
2019-06-08 04:49:28 +02:00
case "${1}" in
-l|--slaze)
theme='slaze'
;;
-s|--stylish)
theme='stylish'
;;
-t|--tela)
theme='tela'
;;
-v|--vimix)
theme='vimix'
;;
-h|--help)
usage
exit 0
;;
*)
prompt -e "\n ERROR: Unrecognized installation option '$1'."
prompt -i "\n Try '$0 --help' for more information."
exit 1
;;
esac
shift
2019-05-31 09:15:27 +02:00
done
2019-06-08 04:49:28 +02:00
install_dialog && install
exit 0