This commit is contained in:
vinceliuice
2021-01-25 23:54:41 +08:00
parent 5871779b04
commit 30c1a9162b
227 changed files with 2329 additions and 1089 deletions
+185 -177
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#! /usr/bin/env bash
# Grub2 Themes
set -o errexit
@@ -14,6 +14,10 @@ THEME_DIR="/usr/share/grub/themes"
REO_DIR="$(cd $(dirname $0) && pwd)"
}
THEME_VARIANTS=('tela' 'vimix' 'stylish' 'slaze' 'whitesur')
ICON_VARIANTS=('color' 'white' 'whitesur')
SCREEN_VARIANTS=('1080p' '2k' '4k' 'ultrawide' 'ultrawide2k')
#COLORS
CDEF=" \033[0m" # default color
CCIN=" \033[0;36m" # info color
@@ -52,142 +56,86 @@ 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" "-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" "-U, --ultrawide2k" "Install 3440x1440 background image"
printf " %-25s%s\n" "-C, --custom-background" "Use either background.jpg or custom-background.jpg as theme background instead"
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" "-t, --theme" "theme variant(s) [tela|vimix|stylish|slaze] (default is tela)"
printf " %-25s%s\n" "-i, --icon" "icon variant(s) [color|white] (default is color)"
printf " %-25s%s\n" "-s, --screen" "screen display variant(s) [1080p|2k|4k|ultrawide|ultrawide2k] (default is 1080p)"
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"
else
prompt -i "\n Run ./install.sh -h for help!"
install_dialog && run_dialog
fi
local theme=${1}
local icon=${2}
local screen=${3}
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"
elif [[ ${screen} == '1440p_21:9' ]]; then
local screen="1440p_21:9"
else
local screen="1080p"
fi
if [[ ${screen} == '1080p_21:9' && ${name} == 'Slaze' ]]; then
if [[ ${screen} == 'ultrawide' && ${theme} == 'Slaze' ]]; then
prompt -e "ultrawide 1080p does not support Slaze theme"
exit 1
elif [[ ${screen} == '1440p_21:9' && ${name} == 'Slaze' ]]; then
elif [[ ${screen} == 'ultrawide2k' && ${theme} == 'Slaze' ]]; then
prompt -e "ultrawide 1440p does not support Slaze theme"
exit 1
fi
if [[ ${custom_background} == 'custom-background' ]]; then
local custom_background="custom-background"
else
local custom_background="default-background"
fi
if [[ ${icon} == 'white' ]]; then
local icon="white"
else
local icon="color"
fi
# Check for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then
if [[ "$UID" -eq "$ROOT_UID" ]]; then
clear
if [[ "${custom_background}" == "custom-background" ]]; then
if [[ -f "background.jpg" ]]; then
custom_background="background.jpg"
elif [[ -f "custom-background.jpg" ]]; then
custom_background="custom-background.jpg"
else
prompt -e "Neither background.jpg, or custom-background.jpg could be found, exiting"
exit 0
fi
fi
# Create themes directory if it didn't exist
echo -e "\n Checking for the existence of themes directory..."
prompt -s "\n Checking for the existence of themes directory..."
[[ -d "${THEME_DIR}/${name}" ]] && rm -rf "${THEME_DIR}/${name}"
mkdir -p "${THEME_DIR}/${name}"
[[ -d "${THEME_DIR}/${theme}" ]] && rm -rf "${THEME_DIR}/${theme}"
mkdir -p "${THEME_DIR}/${theme}"
# Copy theme
prompt -i "\n Installing ${name} ${icon} ${screen} theme..."
prompt -s "\n Installing ${theme} ${icon} ${screen} theme..."
# Don't preserve ownership because the owner will be root, and that causes the script to crash if it is ran from terminal by sudo
cp -a --no-preserve=ownership "${REO_DIR}/common/"{*.png,*.pf2} "${THEME_DIR}/${name}"
cp -a --no-preserve=ownership "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${name}/theme.txt"
cp -a --no-preserve=ownership "${REO_DIR}/common/"{*.png,*.pf2} "${THEME_DIR}/${theme}"
cp -a --no-preserve=ownership "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${theme}/theme.txt"
cp -a --no-preserve=ownership "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${theme}/background.jpg"
if [[ ${custom_background} == "background.jpg" ]] || [[ ${custom_background} == "custom-background.jpg" ]]; then
if [[ -f "$custom_background" ]]; then
prompt -i "\n Using ${custom_background} as background image..."
cp -a --no-preserve=ownership "${REO_DIR}/${custom_background}" "${THEME_DIR}/${name}/background.jpg"
convert -auto-orient "${THEME_DIR}/${name}/background.jpg" "${THEME_DIR}/${name}/background.jpg"
else
prompt -e "$custom_background couldn't be found, exiting"
exit 0
fi
else
cp -a --no-preserve=ownership "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${name}/background.jpg"
# Use custom background.jpg as grub background image
if [[ -f "${REO_DIR}/background.jpg" ]]; then
prompt -w "\n Using custom background.jpg as grub background image..."
cp -a --no-preserve=ownership "${REO_DIR}/background.jpg" "${THEME_DIR}/${theme}/background.jpg"
convert -auto-orient "${THEME_DIR}/${theme}/background.jpg" "${THEME_DIR}/${theme}/background.jpg"
fi
if [[ ${screen} == '1080p_21:9' ]]; then
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-1080p" "${THEME_DIR}/${name}/icons"
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/select-1080p/"*.png "${THEME_DIR}/${name}"
elif [[ ${screen} == '1440p_21:9' ]]; then
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-2k" "${THEME_DIR}/${name}/icons"
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/select-2k/"*.png "${THEME_DIR}/${name}"
if [[ ${screen} == 'ultrawide' ]]; then
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-1080p" "${THEME_DIR}/${theme}/icons"
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-select/select-1080p/"*.png "${THEME_DIR}/${theme}"
elif [[ ${screen} == 'ultrawide2k' ]]; then
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-2k" "${THEME_DIR}/${theme}/icons"
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-select/select-2k/"*.png "${THEME_DIR}/${theme}"
else
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-${screen}" "${THEME_DIR}/${name}/icons"
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/select-${screen}/"*.png "${THEME_DIR}/${name}"
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-${screen}" "${THEME_DIR}/${theme}/icons"
cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-select/select-${screen}/"*.png "${THEME_DIR}/${theme}"
fi
# Set theme
prompt -i "\n Setting ${name} as default..."
prompt -s "\n Setting ${theme} as default..."
# Backup grub config
cp -an /etc/default/grub /etc/default/grub.bak
if grep "GRUB_THEME=" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_THEME
sed -i "s|.*GRUB_THEME=.*|GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"|" /etc/default/grub
sed -i "s|.*GRUB_THEME=.*|GRUB_THEME=\"${THEME_DIR}/${theme}/theme.txt\"|" /etc/default/grub
else
#Append GRUB_THEME
echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub
echo "GRUB_THEME=\"${THEME_DIR}/${theme}/theme.txt\"" >> /etc/default/grub
fi
# Make sure the right resolution for grub is set
if [[ ${screen} == '1080p' ]]; then
gfxmode="GRUB_GFXMODE=1920x1080,auto"
elif [[ ${screen} == '1080p_21:9' ]]; then
elif [[ ${screen} == 'ultrawide' ]]; then
gfxmode="GRUB_GFXMODE=2560x1080,auto"
elif [[ ${screen} == '4k' ]]; then
gfxmode="GRUB_GFXMODE=3840x2160,auto"
elif [[ ${screen} == '2k' ]]; then
gfxmode="GRUB_GFXMODE=2560x1440,auto"
elif [[ ${screen} == '1440p_21:9' ]]; then
elif [[ ${screen} == 'ultrawide2k' ]]; then
gfxmode="GRUB_GFXMODE=3440x1440,auto"
fi
@@ -213,13 +161,14 @@ install() {
if [[ -f "/etc/default/grub.d/kali-themes.cfg" ]]; then
cp -an /etc/default/grub.d/kali-themes.cfg /etc/default/grub.d/kali-themes.cfg.bak
sed -i "s|.*GRUB_GFXMODE=.*|${gfxmode}|" /etc/default/grub.d/kali-themes.cfg
sed -i "s|.*GRUB_THEME=.*|GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"|" /etc/default/grub.d/kali-themes.cfg
sed -i "s|.*GRUB_THEME=.*|GRUB_THEME=\"${THEME_DIR}/${theme}/theme.txt\"|" /etc/default/grub.d/kali-themes.cfg
fi
# Update grub config
prompt -i "\n Updating grub config...\n"
prompt -s "\n Updating grub config...\n"
updating_grub
prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' "
else
#Check if password is cached (if cache timestamp not expired yet)
@@ -227,24 +176,22 @@ install() {
if [[ $? == 0 ]]; then
#No need to ask for password
sudo "$0" --${theme} --${icon} --${screen}
sudo "$0" -t ${theme} -i ${icon} -s ${screen}
else
#Ask for password
if [[ -n ${tui_root_login} ]] ; then
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S $0 --${theme} --${icon} --${screen} <<< ${tui_root_login}
sudo -S $0 -t ${theme} -i ${icon} -s ${screen} <<< ${tui_root_login}
fi
else
prompt -e "\n [ Error! ] -> Run me as root! "
read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
sudo -S echo <<< $REPLY 2> /dev/null && echo
if [[ $? == 0 ]]; then
#Correct password, use with sudo's stdin
sudo -S "$0" --${theme} --${icon} --${screen} <<< ${REPLY}
sudo -S "$0" -t ${theme} -i ${icon} -s ${screen} <<< ${REPLY}
else
#block for 3 seconds before allowing another attempt
sleep 3
@@ -293,22 +240,26 @@ run_dialog() {
1 "Vimix Theme" off \
2 "Tela Theme" on \
3 "Stylish Theme" off \
4 "Slaze Theme" off --output-fd 1 )
4 "Slaze Theme" off \
5 "WhiteSur Theme" off --output-fd 1 )
case "$tui" in
1) theme="vimix" ;;
2) theme="tela" ;;
3) theme="stylish" ;;
4) theme="slaze" ;;
1) theme="vimix" ;;
2) theme="tela" ;;
3) theme="stylish" ;;
4) theme="slaze" ;;
5) theme="whitesur" ;;
*) operation_canceled ;;
esac
tui=$(dialog --backtitle ${Project_Name} \
--radiolist "Choose icon style : " 15 40 5 \
1 "white" off \
2 "color" on --output-fd 1 )
2 "color" on \
3 "whitesur" off --output-fd 1 )
case "$tui" in
1) icon="white" ;;
2) icon="color" ;;
1) icon="white" ;;
2) icon="color" ;;
3) icon="whitesur" ;;
*) operation_canceled ;;
esac
@@ -320,19 +271,19 @@ run_dialog() {
4 "4k (3840x2160)" off \
5 "1440p ultrawide (3440x1440)" off --output-fd 1 )
case "$tui" in
1) screen="1080p" ;;
2) screen="1080p_21:9" ;;
3) screen="2k" ;;
4) screen="4k" ;;
5) screen="1440p_21:9";;
*) operation_canceled ;;
1) screen="1080p" ;;
2) screen="ultrawide" ;;
3) screen="2k" ;;
4) screen="4k" ;;
5) screen="ultrawide2k" ;;
*) operation_canceled ;;
esac
fi
}
operation_canceled() {
clear
prompt -i "\n Operation canceled by user, Bye!"
prompt -i "\n Operation canceled by user, Bye!"
exit 1
}
@@ -353,7 +304,7 @@ updating_grub() {
install_dialog() {
if [ ! "$(which dialog 2> /dev/null)" ]; then
prompt -i "\n 'dialog' need to be installed for this shell"
prompt -w "\n 'dialog' need to be installed for this shell"
if has_command zypper; then
sudo zypper in dialog
elif has_command apt-get; then
@@ -369,26 +320,15 @@ install_dialog() {
}
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"
else
prompt -i "\n Run ./install.sh -h for help!"
exit 0
fi
local theme=${1}
# Check 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}"
if [[ -d "${THEME_DIR}/${theme}" ]]; then
rm -rf "${THEME_DIR}/${theme}"
else
prompt -i "\n ${name} grub theme not exist!"
prompt -e "\n ${theme} grub theme not exist!"
exit 0
fi
@@ -396,20 +336,18 @@ remove() {
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!"
prompt -e "\n grub.bak not exist!"
exit 0
fi
# For Kali linux
if [[ -f "/etc/default/grub.d/kali-themes.cfg.bak" ]]; then
rm -rf /etc/default/grub.d/kali-themes.cfg && mv /etc/default/grub.d/kali-themes.cfg.bak /etc/default/grub.d/kali-themes.cfg
else
prompt -i "\n kali-themes.cfg.bak not exist!"
exit 0
fi
# Update grub config
prompt -i "\n Resetting grub theme...\n"
prompt -s "\n Resetting grub theme...\n"
updating_grub
else
@@ -471,68 +409,138 @@ if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ ! -x /usr/bin/dialog ]] ; t
fi
fi
while [[ $# -ge 1 ]]; do
while [[ $# -gt 0 ]]; do
PROG_ARGS+=("${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'
;;
-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'
;;
-U|--ultrawide2k|--1440p_21:9)
screen='1440p_21:9'
;;
-C|--custom-background|--custom)
custom_background='custom-background'
shift 1
;;
-r|--remove)
remove='true'
shift 1
;;
-t|--theme)
shift
for theme in "${@}"; do
case "${theme}" in
tela)
themes+=("${THEME_VARIANTS[0]}")
shift
;;
vimix)
themes+=("${THEME_VARIANTS[1]}")
shift
;;
stylish)
themes+=("${THEME_VARIANTS[2]}")
shift
;;
slaze)
themes+=("${THEME_VARIANTS[3]}")
shift
;;
whitesur)
themes+=("${THEME_VARIANTS[4]}")
shift
;;
-*|--*)
break
;;
*)
prompt -e "ERROR: Unrecognized theme variant '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
done
;;
-i|--icon)
shift
for icon in "${@}"; do
case "${icon}" in
color)
icons+=("${ICON_VARIANTS[0]}")
shift
;;
white)
icons+=("${ICON_VARIANTS[1]}")
shift
;;
whitesur)
icons+=("${ICON_VARIANTS[2]}")
shift
;;
-*|--*)
break
;;
*)
prompt -e "ERROR: Unrecognized icon variant '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
done
;;
-s|--screen)
shift
for screen in "${@}"; do
case "${screen}" in
1080p)
screens+=("${SCREEN_VARIANTS[0]}")
shift
;;
2k)
screens+=("${SCREEN_VARIANTS[1]}")
shift
;;
4k)
screens+=("${SCREEN_VARIANTS[2]}")
shift
;;
ultrawide)
screens+=("${SCREEN_VARIANTS[3]}")
shift
;;
ultrawide2k)
screens+=("${SCREEN_VARIANTS[4]}")
shift
;;
-*|--*)
break
;;
*)
prompt -e "ERROR: Unrecognized icon variant '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
done
;;
-h|--help)
usage
exit 0
;;
*)
prompt -e "\n ERROR: Unrecognized installation option '$1'."
prompt -i "Try '$0 --help' for more information."
prompt -e "ERROR: Unrecognized installation option '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
shift
done
if [[ "${remove:-}" != 'true' ]]; then
install
for theme in "${themes[@]-${THEME_VARIANTS[0]}}"; do
for icon in "${icons[@]-${ICON_VARIANTS[0]}}"; do
for screen in "${screens[@]-${SCREEN_VARIANTS[0]}}"; do
install "${theme}" "${icon}" "${screen}"
done
done
done
elif [[ "${remove:-}" == 'true' ]]; then
remove
for theme in "${themes[@]-${THEME_VARIANTS[0]}}"; do
remove "${theme}"
done
fi
exit 0