mirror of
https://github.com/vinceliuice/grub2-themes.git
synced 2024-12-25 20:25:35 +01:00
Merge pull request #151 from The-Plottwist/master
Pull request for 149'th issue
This commit is contained in:
commit
468bee78f5
187
install.sh
187
install.sh
@ -1,24 +1,16 @@
|
|||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
# Grub2 Themes
|
|
||||||
|
# Exit Immediately if a command fails
|
||||||
set -o errexit
|
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)"
|
# ──────────────────────────────────────────────────── I ──────────
|
||||||
}
|
# :::::: C O L O R S : : : : : : : :
|
||||||
|
# ──────────────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
|
||||||
THEME_VARIANTS=('tela' 'vimix' 'stylish' 'whitesur')
|
|
||||||
ICON_VARIANTS=('color' 'white' 'whitesur')
|
|
||||||
SCREEN_VARIANTS=('1080p' '2k' '4k' 'ultrawide' 'ultrawide2k')
|
|
||||||
|
|
||||||
#COLORS
|
|
||||||
CDEF=" \033[0m" # default color
|
CDEF=" \033[0m" # default color
|
||||||
CCIN=" \033[0;36m" # info color
|
CCIN=" \033[0;36m" # info color
|
||||||
CGSC=" \033[0;32m" # success color
|
CGSC=" \033[0;32m" # success color
|
||||||
@ -30,6 +22,32 @@ b_CGSC=" \033[1;32m" # bold success color
|
|||||||
b_CRER=" \033[1;31m" # bold error color
|
b_CRER=" \033[1;31m" # bold error color
|
||||||
b_CWAR=" \033[1;33m" # bold warning color
|
b_CWAR=" \033[1;33m" # bold warning color
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# ────────────────────────────────────────────────────── II ──────────
|
||||||
|
# :::::: G L O B A L S : : : : : : : :
|
||||||
|
# ────────────────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
|
||||||
|
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)"
|
||||||
|
|
||||||
|
THEME_VARIANTS=('tela' 'vimix' 'stylish' 'whitesur')
|
||||||
|
ICON_VARIANTS=('color' 'white' 'whitesur')
|
||||||
|
SCREEN_VARIANTS=('1080p' '2k' '4k' 'ultrawide' 'ultrawide2k')
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# ────────────────────────────────────────────────────────── III ──────────
|
||||||
|
# :::::: F U N C T I O N S : : : : : : : :
|
||||||
|
# ────────────────────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
|
||||||
# echo like ... with flag type and display message colors
|
# echo like ... with flag type and display message colors
|
||||||
prompt () {
|
prompt () {
|
||||||
case ${1} in
|
case ${1} in
|
||||||
@ -49,7 +67,7 @@ prompt () {
|
|||||||
|
|
||||||
# Check command availability
|
# Check command availability
|
||||||
function has_command() {
|
function has_command() {
|
||||||
command -v $1 > /dev/null
|
command -v $1 &> /dev/null #with "&>", all output will be redirected.
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@ -72,7 +90,7 @@ install() {
|
|||||||
if [[ "$UID" -eq "$ROOT_UID" ]]; then
|
if [[ "$UID" -eq "$ROOT_UID" ]]; then
|
||||||
clear
|
clear
|
||||||
|
|
||||||
# Create themes directory if it didn't exist
|
# Make a themes directory if it doesn't exist
|
||||||
prompt -s "\n Checking for the existence of themes directory..."
|
prompt -s "\n Checking for the existence of themes directory..."
|
||||||
|
|
||||||
[[ -d "${THEME_DIR}/${theme}" ]] && rm -rf "${THEME_DIR}/${theme}"
|
[[ -d "${THEME_DIR}/${theme}" ]] && rm -rf "${THEME_DIR}/${theme}"
|
||||||
@ -187,29 +205,31 @@ install() {
|
|||||||
updating_grub
|
updating_grub
|
||||||
|
|
||||||
prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' "
|
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)
|
|
||||||
sudo -n true 2> /dev/null && echo
|
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
#Check if password is cached (if cache timestamp has not expired yet)
|
||||||
#No need to ask for password
|
elif sudo -n true 2> /dev/null && echo; then #No need for "$?" ==> https://github.com/koalaman/shellcheck/wiki/SC2181
|
||||||
|
|
||||||
sudo "$0" -t ${theme} -i ${icon} -s ${screen}
|
sudo "$0" -t ${theme} -i ${icon} -s ${screen}
|
||||||
else
|
else
|
||||||
|
|
||||||
#Ask for password
|
#Ask for password
|
||||||
if [[ -n ${tui_root_login} ]] ; then
|
if [[ -n ${tui_root_login} ]] ; then
|
||||||
|
|
||||||
if [[ -n "${theme}" && -n "${screen}" ]]; then
|
if [[ -n "${theme}" && -n "${screen}" ]]; then
|
||||||
|
|
||||||
sudo -S $0 -t ${theme} -i ${icon} -s ${screen} <<< ${tui_root_login}
|
sudo -S $0 -t ${theme} -i ${icon} -s ${screen} <<< ${tui_root_login}
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
||||||
prompt -e "\n [ Error! ] -> Run me as root! "
|
prompt -e "\n [ Error! ] -> Run me as root! "
|
||||||
read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
|
read -r -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
|
||||||
|
|
||||||
sudo -S echo <<< $REPLY 2> /dev/null && echo
|
if sudo -S echo <<< $REPLY 2> /dev/null && echo; then
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
|
||||||
#Correct password, use with sudo's stdin
|
#Correct password, use with sudo's stdin
|
||||||
sudo -S "$0" -t ${theme} -i ${icon} -s ${screen} <<< ${REPLY}
|
sudo -S "$0" -t ${theme} -i ${icon} -s ${screen} <<< ${REPLY}
|
||||||
else
|
else
|
||||||
|
|
||||||
#block for 3 seconds before allowing another attempt
|
#block for 3 seconds before allowing another attempt
|
||||||
sleep 3
|
sleep 3
|
||||||
prompt -e "\n [ Error! ] -> Incorrect password!\n"
|
prompt -e "\n [ Error! ] -> Incorrect password!\n"
|
||||||
@ -217,16 +237,13 @@ install() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_dialog() {
|
run_dialog() {
|
||||||
if [[ -x /usr/bin/dialog ]]; then
|
if [[ -x /usr/bin/dialog ]]; then
|
||||||
if [[ "$UID" -ne "$ROOT_UID" ]]; then
|
if [[ "$UID" -ne "$ROOT_UID" ]]; then
|
||||||
#Check if password is cached (if cache timestamp not expired yet)
|
#Check if password is cached (if cache timestamp not expired yet)
|
||||||
sudo -n true 2> /dev/null && echo
|
if sudo -n true 2> /dev/null && echo; then
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
|
||||||
#No need to ask for password
|
#No need to ask for password
|
||||||
sudo $0
|
sudo $0
|
||||||
else
|
else
|
||||||
@ -237,9 +254,7 @@ run_dialog() {
|
|||||||
--passwordbox "require root permission" 8 50 \
|
--passwordbox "require root permission" 8 50 \
|
||||||
--output-fd 1 )
|
--output-fd 1 )
|
||||||
|
|
||||||
sudo -S echo <<< $tui_root_login 2> /dev/null && echo
|
if sudo -S echo <<< $tui_root_login 2> /dev/null && echo; then
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
|
||||||
#Correct password, use with sudo's stdin
|
#Correct password, use with sudo's stdin
|
||||||
sudo -S "$0" <<< $tui_root_login
|
sudo -S "$0" <<< $tui_root_login
|
||||||
else
|
else
|
||||||
@ -324,20 +339,30 @@ updating_grub() {
|
|||||||
prompt -s "\n * All done!"
|
prompt -s "\n * All done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function install_program () {
|
||||||
|
|
||||||
|
if has_command zypper; then
|
||||||
|
|
||||||
|
zypper in "$@"
|
||||||
|
elif has_command apt-get; then
|
||||||
|
|
||||||
|
apt-get install "$@"
|
||||||
|
elif has_command dnf; then
|
||||||
|
|
||||||
|
dnf install -y "$@"
|
||||||
|
elif has_command yum; then
|
||||||
|
|
||||||
|
yum install "$@"
|
||||||
|
elif has_command pacman; then
|
||||||
|
|
||||||
|
pacman -S --noconfirm "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
install_dialog() {
|
install_dialog() {
|
||||||
if [ ! "$(which dialog 2> /dev/null)" ]; then
|
if [ ! "$(which dialog 2> /dev/null)" ]; then
|
||||||
prompt -w "\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
|
install_program "dialog"
|
||||||
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,47 +371,58 @@ remove() {
|
|||||||
|
|
||||||
# Check for root access and proceed if it is present
|
# Check for root access and proceed if it is present
|
||||||
if [ "$UID" -eq "$ROOT_UID" ]; then
|
if [ "$UID" -eq "$ROOT_UID" ]; then
|
||||||
|
|
||||||
echo -e "\n Checking for the existence of themes directory..."
|
echo -e "\n Checking for the existence of themes directory..."
|
||||||
if [[ -d "${THEME_DIR}/${theme}" ]]; then
|
if [[ -d "${THEME_DIR}/${theme}" ]]; then
|
||||||
rm -rf "${THEME_DIR}/${theme}"
|
rm -rf "${THEME_DIR}/${theme}"
|
||||||
else
|
else
|
||||||
prompt -e "\n ${theme} grub theme not exist!"
|
prompt -e "\n Specified ${theme} theme does not exist!"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Backup grub config
|
local grub_config_location=""
|
||||||
if [[ -f "/etc/default/grub.bak" ]]; then
|
if [[ -f "/etc/default/grub" ]]; then
|
||||||
rm -rf /etc/default/grub && mv /etc/default/grub.bak /etc/default/grub
|
|
||||||
|
grub_config_location="/etc/default/grub"
|
||||||
|
elif [[ -f "/etc/default/grub.d/kali-themes.cfg" ]]; then
|
||||||
|
|
||||||
|
grub_config_location="/etc/default/grub.d/kali-themes.cfg"
|
||||||
else
|
else
|
||||||
prompt -e "\n grub.bak not exist!"
|
|
||||||
exit 0
|
prompt -e "\nCannot find grub config file in default locations!"
|
||||||
|
prompt -e "\nPlease inform the developers by opening an issue on github."
|
||||||
|
prompt -e "\nExiting..."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For Kali linux
|
local current_theme="" # Declaration and assignment should be done seperately ==> https://github.com/koalaman/shellcheck/wiki/SC2155
|
||||||
if [[ -f "/etc/default/grub.d/kali-themes.cfg.bak" ]]; then
|
current_theme="$(grep 'GRUB_THEME=' $grub_config_location | grep -v \#)"
|
||||||
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
|
if [[ -n "$current_theme" ]]; then
|
||||||
fi
|
|
||||||
|
# Backup with --in-place option to grub.bak within the same directory; then remove the current theme.
|
||||||
|
sed --in-place='.bak' "s|$current_theme|#GRUB_THEME=|" "$grub_config_location"
|
||||||
|
|
||||||
# Update grub config
|
# Update grub config
|
||||||
prompt -s "\n Resetting grub theme...\n"
|
prompt -s "\n Resetting grub theme...\n"
|
||||||
|
|
||||||
updating_grub
|
updating_grub
|
||||||
|
else
|
||||||
|
|
||||||
|
prompt -e "\nNo active theme found."
|
||||||
|
prompt -e "\nExiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
#Check if password is cached (if cache timestamp not expired yet)
|
#Check if password is cached (if cache timestamp not expired yet)
|
||||||
sudo -n true 2> /dev/null && echo
|
if sudo -n true 2> /dev/null && echo; then
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
|
||||||
#No need to ask for password
|
#No need to ask for password
|
||||||
sudo "$0" "${PROG_ARGS[@]}"
|
sudo "$0" "${PROG_ARGS[@]}"
|
||||||
else
|
else
|
||||||
#Ask for password
|
#Ask for password
|
||||||
prompt -e "\n [ Error! ] -> Run me as root! "
|
prompt -e "\n [ Error! ] -> Run me as root! "
|
||||||
read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
|
read -r -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s #when using "read" command, "-r" option must be supplied ==> https://github.com/koalaman/shellcheck/wiki/SC2162
|
||||||
|
|
||||||
sudo -S echo <<< $REPLY 2> /dev/null && echo
|
if sudo -S echo <<< $REPLY 2> /dev/null && echo; then
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
|
||||||
#Correct password, use with sudo's stdin
|
#Correct password, use with sudo's stdin
|
||||||
sudo -S "$0" "${PROG_ARGS[@]}" <<< $REPLY
|
sudo -S "$0" "${PROG_ARGS[@]}" <<< $REPLY
|
||||||
else
|
else
|
||||||
@ -404,19 +440,16 @@ dialog_installer() {
|
|||||||
if [[ ! -x /usr/bin/dialog ]]; then
|
if [[ ! -x /usr/bin/dialog ]]; then
|
||||||
if [[ $UID -ne $ROOT_UID ]]; then
|
if [[ $UID -ne $ROOT_UID ]]; then
|
||||||
#Check if password is cached (if cache timestamp not expired yet)
|
#Check if password is cached (if cache timestamp not expired yet)
|
||||||
sudo -n true 2> /dev/null && echo
|
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
if sudo -n true 2> /dev/null && echo; then
|
||||||
#No need to ask for password
|
#No need to ask for password
|
||||||
exec sudo $0
|
exec sudo $0
|
||||||
else
|
else
|
||||||
#Ask for password
|
#Ask for password
|
||||||
prompt -e "\n [ Error! ] -> Run me as root! "
|
prompt -e "\n [ Error! ] -> Run me as root! "
|
||||||
read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
|
read -r -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
|
||||||
|
|
||||||
sudo -S echo <<< $REPLY 2> /dev/null && echo
|
if sudo -S echo <<< $REPLY 2> /dev/null && echo; then
|
||||||
|
|
||||||
if [[ $? == 0 ]]; then
|
|
||||||
#Correct password, use with sudo's stdin
|
#Correct password, use with sudo's stdin
|
||||||
sudo $0 <<< $REPLY
|
sudo $0 <<< $REPLY
|
||||||
else
|
else
|
||||||
@ -433,6 +466,13 @@ dialog_installer() {
|
|||||||
install "${theme}" "${icon}" "${screen}"
|
install "${theme}" "${icon}" "${screen}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# ────────────────────────────────────────────────────────────────────────── IV ──────────
|
||||||
|
# :::::: A R G U M E N T H A N D L I N G : : : : : : : :
|
||||||
|
# ────────────────────────────────────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
PROG_ARGS+=("${1}")
|
PROG_ARGS+=("${1}")
|
||||||
dialog='false'
|
dialog='false'
|
||||||
@ -465,7 +505,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
themes+=("${THEME_VARIANTS[3]}")
|
themes+=("${THEME_VARIANTS[3]}")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-*|--*)
|
-*) # "-*" overrides "--*"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -492,7 +532,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
icons+=("${ICON_VARIANTS[2]}")
|
icons+=("${ICON_VARIANTS[2]}")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-*|--*)
|
-*)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -527,7 +567,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
screens+=("${SCREEN_VARIANTS[4]}")
|
screens+=("${SCREEN_VARIANTS[4]}")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-*|--*)
|
-*)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -550,6 +590,13 @@ while [[ $# -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# ──────────────────────────────────────────────── V ──────────
|
||||||
|
# :::::: M A I N : : : : : : : :
|
||||||
|
# ──────────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
|
||||||
# Show terminal user interface for better use
|
# Show terminal user interface for better use
|
||||||
if [[ "${dialog:-}" == 'false' ]]; then
|
if [[ "${dialog:-}" == 'false' ]]; then
|
||||||
if [[ "${remove:-}" != 'true' ]]; then
|
if [[ "${remove:-}" != 'true' ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user