grub2-themes/install.sh

684 lines
22 KiB
Bash
Raw Permalink Normal View History

2021-01-25 16:54:41 +01:00
#! /usr/bin/env bash
2019-05-31 09:15:27 +02:00
# Exit Immediately if a command fails
set -o errexit
2020-02-23 01:31:37 +01:00
readonly ROOT_UID=0
readonly Project_Name="GRUB2::THEMES"
readonly MAX_DELAY=20 # max delay for user to enter root password
tui_root_login=
2019-05-31 09:15:27 +02:00
2020-02-23 01:31:37 +01:00
THEME_DIR="/usr/share/grub/themes"
2019-08-30 03:55:07 +02:00
REO_DIR="$(cd $(dirname $0) && pwd)"
2019-06-08 04:49:28 +02:00
2021-12-05 07:12:59 +01:00
THEME_VARIANTS=('tela' 'vimix' 'stylish' 'whitesur')
2021-01-25 16:54:41 +01:00
ICON_VARIANTS=('color' 'white' 'whitesur')
SCREEN_VARIANTS=('1080p' '2k' '4k' 'ultrawide' 'ultrawide2k')
2022-01-22 11:29:10 +01:00
#################################
# :::::: C O L O R S :::::: #
#################################
2022-01-22 11:29:10 +01:00
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
#######################################
# :::::: F U N C T I O N S :::::: #
#######################################
2019-06-08 04:49:28 +02:00
# echo like ... with flag type and display message colors
2019-06-08 04:49:28 +02:00
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
}
2020-11-10 12:46:53 +01:00
# Check command availability
2019-05-31 09:15:27 +02:00
function has_command() {
command -v $1 &> /dev/null #with "&>", all output will be redirected.
2019-05-31 09:15:27 +02:00
}
usage() {
2022-10-30 16:36:05 +01:00
cat << EOF
Usage: $0 [OPTION]...
OPTIONS:
-t, --theme theme variant(s) [tela|vimix|stylish|whitesur] (default is tela)
-i, --icon icon variant(s) [color|white|whitesur] (default is color)
-s, --screen screen display variant(s) [1080p|2k|4k|ultrawide|ultrawide2k] (default is 1080p)
-r, --remove Remove theme [tela|vimix|stylish|whitesur] (must add theme name option, default is tela)
-b, --boot install theme into '/boot/grub' or '/boot/grub2'
-g, --generate do not install but generate theme into chosen directory (must add your directory)
-h, --help Show this help
EOF
2019-05-31 09:15:27 +02:00
}
2022-02-21 04:26:29 +01:00
generate() {
2022-10-30 16:20:45 +01:00
if [[ "${install_boot}" == 'true' ]]; then
if [[ -d "/boot/grub" ]]; then
THEME_DIR='/boot/grub/themes'
fi
if [[ -d "/boot/grub2" ]]; then
2022-10-30 16:20:45 +01:00
THEME_DIR='/boot/grub2/themes'
fi
fi
2022-03-19 03:32:20 +01:00
# Make a themes directory if it doesn't exist
2023-04-15 17:05:00 +02:00
prompt -i "\n Checking for the existence of themes directory..."
2019-06-08 04:49:28 +02:00
2022-03-19 03:32:20 +01:00
[[ -d "${THEME_DIR}/${theme}" ]] && rm -rf "${THEME_DIR}/${theme}"
mkdir -p "${THEME_DIR}/${theme}"
2019-05-31 09:51:14 +02:00
2022-03-19 03:32:20 +01:00
# Copy theme
2023-04-15 17:05:00 +02:00
prompt -i "\n Installing ${theme} ${icon} ${screen} theme..."
2019-05-31 09:51:14 +02:00
2022-03-19 03:32:20 +01:00
# 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}/${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"
2021-01-25 16:54:41 +01:00
2022-03-19 03:32:20 +01:00
# 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
2019-05-31 09:15:27 +02:00
2022-03-19 03:32:20 +01:00
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}"
cp -a --no-preserve=ownership "${REO_DIR}/assets/info-1080p.png" "${THEME_DIR}/${theme}/info.png"
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}"
cp -a --no-preserve=ownership "${REO_DIR}/assets/info-2k.png" "${THEME_DIR}/${theme}/info.png"
else
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}"
cp -a --no-preserve=ownership "${REO_DIR}/assets/info-${screen}.png" "${THEME_DIR}/${theme}/info.png"
fi
2022-02-21 04:26:29 +01:00
}
install() {
local theme=${1}
local icon=${2}
local screen=${3}
# Check for root access and proceed if it is present
if [[ "$UID" -eq "$ROOT_UID" ]]; then
# Generate the theme in "/usr/share/grub/themes"
generate "${theme}" "${icon}" "${screen}"
2019-05-31 09:51:14 +02:00
# Set theme
2023-04-15 17:05:00 +02:00
prompt -i "\n Setting ${theme} as default..."
2019-05-31 09:51:14 +02:00
2019-08-30 03:55:07 +02:00
# Backup grub config
2023-07-21 17:09:52 +02:00
if [[ -f /etc/default/grub.bak ]]; then
2023-07-21 18:31:33 +02:00
prompt -w "\n File '/etc/default/grub.bak' already exists!"
# read choice
# if [[ "$choice" = 'y' ]]; then
# cp -a /etc/default/grub /etc/default/grub.bak
# else
# prompt -s "Skipping to save a backup configuration in '/etc/default/grub.bak'"
# fi
2023-07-21 17:09:52 +02:00
else
2023-07-21 18:31:33 +02:00
cp -an /etc/default/grub /etc/default/grub.bak
2023-07-21 17:09:52 +02:00
fi
2021-06-01 04:54:29 +02:00
2021-05-08 01:14:55 +02:00
# Fedora workaround to fix the missing unicode.pf2 file (tested on fedora 34): https://bugzilla.redhat.com/show_bug.cgi?id=1739762
# This occurs when we add a theme on grub2 with Fedora.
2021-10-16 17:46:24 +02:00
if has_command dnf; then
if [[ -f "/boot/grub2/fonts/unicode.pf2" ]]; then
if grep "GRUB_FONT=" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_FONT
sed -i "s|.*GRUB_FONT=.*|GRUB_FONT=/boot/grub2/fonts/unicode.pf2|" /etc/default/grub
else
#Append GRUB_FONT
echo "GRUB_FONT=/boot/grub2/fonts/unicode.pf2" >> /etc/default/grub
fi
2024-08-19 08:18:26 +02:00
elif [[ -f "/boot/efi/EFI/fedora/fonts/unicode.pf2" ]]; then
if grep "GRUB_FONT=" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_FONT
sed -i "s|.*GRUB_FONT=.*|GRUB_FONT=/boot/efi/EFI/fedora/fonts/unicode.pf2|" /etc/default/grub
else
#Append GRUB_FONT
echo "GRUB_FONT=/boot/efi/EFI/fedora/fonts/unicode.pf2" >> /etc/default/grub
fi
2021-10-16 17:46:24 +02:00
fi
fi
2019-08-30 03:55:07 +02:00
if grep "GRUB_THEME=" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_THEME
2021-01-25 16:54:41 +01:00
sed -i "s|.*GRUB_THEME=.*|GRUB_THEME=\"${THEME_DIR}/${theme}/theme.txt\"|" /etc/default/grub
else
#Append GRUB_THEME
2021-01-25 16:54:41 +01:00
echo "GRUB_THEME=\"${THEME_DIR}/${theme}/theme.txt\"" >> /etc/default/grub
fi
2020-01-08 11:53:36 +01:00
if grep "GRUB_BACKGROUND=" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_BACKGROUND
sed -i "s|.*GRUB_BACKGROUND=.*|GRUB_BACKGROUND=\"${THEME_DIR}/${theme}/background.jpg\"|" /etc/default/grub
else
#Append GRUB_BACKGROUND
echo "GRUB_BACKGROUND=\"${THEME_DIR}/${theme}/background.jpg\"" >> /etc/default/grub
fi
2020-11-10 12:46:53 +01:00
# Make sure the right resolution for grub is set
2020-05-04 07:07:19 +02:00
if [[ ${screen} == '1080p' ]]; then
gfxmode="GRUB_GFXMODE=1920x1080,auto"
2021-01-25 16:54:41 +01:00
elif [[ ${screen} == 'ultrawide' ]]; then
gfxmode="GRUB_GFXMODE=2560x1080,auto"
2020-05-04 07:07:19 +02:00
elif [[ ${screen} == '4k' ]]; then
gfxmode="GRUB_GFXMODE=3840x2160,auto"
2020-05-04 07:07:19 +02:00
elif [[ ${screen} == '2k' ]]; then
gfxmode="GRUB_GFXMODE=2560x1440,auto"
2021-01-25 16:54:41 +01:00
elif [[ ${screen} == 'ultrawide2k' ]]; then
2021-01-07 23:28:48 +01:00
gfxmode="GRUB_GFXMODE=3440x1440,auto"
fi
if grep "GRUB_GFXMODE=" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_GFXMODE
sed -i "s|.*GRUB_GFXMODE=.*|${gfxmode}|" /etc/default/grub
else
#Append GRUB_GFXMODE
echo "${gfxmode}" >> /etc/default/grub
2020-05-04 07:07:19 +02:00
fi
2019-05-31 09:51:14 +02:00
if grep "GRUB_TERMINAL=console" /etc/default/grub 2>&1 >/dev/null || grep "GRUB_TERMINAL=\"console\"" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_TERMINAL
sed -i "s|.*GRUB_TERMINAL=.*|#GRUB_TERMINAL=console|" /etc/default/grub
fi
if grep "GRUB_TERMINAL_OUTPUT=console" /etc/default/grub 2>&1 >/dev/null || grep "GRUB_TERMINAL_OUTPUT=\"console\"" /etc/default/grub 2>&1 >/dev/null; then
#Replace GRUB_TERMINAL_OUTPUT
sed -i "s|.*GRUB_TERMINAL_OUTPUT=.*|#GRUB_TERMINAL_OUTPUT=console|" /etc/default/grub
fi
2021-01-25 09:49:21 +01:00
# For Kali linux
2023-04-15 17:05:00 +02:00
if [[ -f "/etc/default/grub.d/kali-themes.cfg" && ! -f "/etc/default/grub.d/kali-themes.cfg.bak" ]]; then
2021-01-25 09:49:21 +01:00
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
2021-01-25 16:54:41 +01:00
sed -i "s|.*GRUB_THEME=.*|GRUB_THEME=\"${THEME_DIR}/${theme}/theme.txt\"|" /etc/default/grub.d/kali-themes.cfg
2021-01-25 09:49:21 +01:00
fi
2019-05-31 09:51:14 +02:00
# Update grub config
2023-07-21 17:09:52 +02:00
prompt -i "\n Updating grub config... \n"
updating_grub
2023-07-21 17:09:52 +02:00
prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' \n"
#Check if password is cached (if cache timestamp has not expired yet)
2022-03-19 03:32:20 +01:00
elif sudo -n true 2> /dev/null && echo; then
2022-10-30 16:20:45 +01:00
if [[ "${install_boot}" == 'true' ]]; then
sudo "$0" -t ${theme} -i ${icon} -s ${screen} -b
else
sudo "$0" -t ${theme} -i ${icon} -s ${screen}
fi
else
#Ask for password
if [[ -n ${tui_root_login} ]] ; then
if [[ -n "${theme}" && -n "${screen}" ]]; then
2022-10-30 16:20:45 +01:00
if [[ "${install_boot}" == 'true' ]]; then
sudo -S $0 -t ${theme} -i ${icon} -s ${screen} -b <<< ${tui_root_login}
else
sudo -S $0 -t ${theme} -i ${icon} -s ${screen} <<< ${tui_root_login}
fi
fi
else
prompt -e "\n [ Error! ] -> Run me as root! "
read -r -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
if sudo -S echo <<< $REPLY 2> /dev/null && echo; then
#Correct password, use with sudo's stdin
2022-10-30 16:20:45 +01:00
if [[ "${install_boot}" == 'true' ]]; then
sudo -S "$0" -t ${theme} -i ${icon} -s ${screen} -b <<< ${REPLY}
else
sudo -S "$0" -t ${theme} -i ${icon} -s ${screen} <<< ${REPLY}
fi
else
#block for 3 seconds before allowing another attempt
sleep 3
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi
2020-02-23 01:31:37 +01:00
fi
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
if [[ "$UID" -ne "$ROOT_UID" ]]; then
#Check if password is cached (if cache timestamp not expired yet)
if sudo -n true 2> /dev/null && echo; then
#No need to ask for password
sudo $0
else
#Ask for password
tui_root_login=$(dialog --backtitle ${Project_Name} \
--title "ROOT LOGIN" \
--insecure \
--passwordbox "require root permission" 8 50 \
--output-fd 1 )
2021-06-01 04:54:29 +02:00
if sudo -S echo <<< $tui_root_login 2> /dev/null && echo; then
#Correct password, use with sudo's stdin
sudo -S "$0" <<< $tui_root_login
else
#block for 3 seconds before allowing another attempt
sleep 3
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi
fi
fi
2020-08-24 12:36:25 +02:00
2020-02-23 01:31:37 +01:00
tui=$(dialog --backtitle ${Project_Name} \
2021-12-05 07:12:59 +01:00
--radiolist "Choose your Grub theme background picture : " 15 40 5 \
2019-06-09 02:12:47 +02:00
1 "Vimix Theme" off \
2 "Tela Theme" on \
3 "Stylish Theme" off \
2021-12-05 07:12:59 +01:00
4 "WhiteSur Theme" off --output-fd 1 )
2019-06-08 04:49:28 +02:00
case "$tui" in
2021-01-25 16:54:41 +01:00
1) theme="vimix" ;;
2) theme="tela" ;;
3) theme="stylish" ;;
2021-12-05 07:12:59 +01:00
4) theme="whitesur" ;;
2020-01-25 17:24:33 +01:00
*) operation_canceled ;;
2019-06-08 04:49:28 +02:00
esac
2020-01-25 18:22:00 +01:00
2020-02-23 01:31:37 +01:00
tui=$(dialog --backtitle ${Project_Name} \
2019-12-05 10:55:00 +01:00
--radiolist "Choose icon style : " 15 40 5 \
1 "white" off \
2021-01-25 16:54:41 +01:00
2 "color" on \
3 "whitesur" off --output-fd 1 )
2019-12-05 10:55:00 +01:00
case "$tui" in
2021-01-25 16:54:41 +01:00
1) icon="white" ;;
2) icon="color" ;;
3) icon="whitesur" ;;
2020-01-25 17:24:33 +01:00
*) operation_canceled ;;
2019-12-05 10:55:00 +01:00
esac
2020-01-25 18:22:00 +01:00
2020-02-23 01:31:37 +01:00
tui=$(dialog --backtitle ${Project_Name} \
2019-10-23 14:32:32 +02:00
--radiolist "Choose your Display Resolution : " 15 40 5 \
2020-06-20 16:53:17 +02:00
1 "1080p (1920x1080)" on \
2 "1080p ultrawide (2560x1080)" off \
3 "2k (2560x1440)" off \
2021-01-07 23:28:48 +01:00
4 "4k (3840x2160)" off \
5 "1440p ultrawide (3440x1440)" off --output-fd 1 )
2019-10-23 14:32:32 +02:00
case "$tui" in
2021-01-25 16:54:41 +01:00
1) screen="1080p" ;;
2) screen="ultrawide" ;;
3) screen="2k" ;;
4) screen="4k" ;;
5) screen="ultrawide2k" ;;
*) operation_canceled ;;
2019-10-23 14:32:32 +02:00
esac
2024-08-19 08:18:26 +02:00
2024-08-19 08:26:40 +02:00
# clear
echo -e '\0033\0143'
2019-06-08 04:49:28 +02:00
fi
}
2020-01-25 17:24:33 +01:00
operation_canceled() {
2021-01-25 16:54:41 +01:00
prompt -i "\n Operation canceled by user, Bye!"
2020-01-25 17:24:33 +01:00
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
# Check for OpenSuse (regular or microOS)
elif has_command zypper || has_command transactional-update; then
grub2-mkconfig -o /boot/grub2/grub.cfg
# Check for Fedora (regular or Atomic)
2024-08-19 08:18:26 +02:00
elif has_command dnf || has_command rpm-ostree; then
# Check for UEFI
if [[ -f /boot/efi/EFI/fedora/grub.cfg ]]; then
prompt -s "Find config file on /boot/efi/EFI/fedora/grub.cfg ...\n"
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
# Check for BIOS
elif [[ -f /boot/grub2/grub.cfg ]]; then
2023-07-21 17:15:11 +02:00
prompt -s "Find config file on /boot/grub2/grub.cfg ...\n"
2021-09-26 15:38:42 +02:00
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
fi
# Success message
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
}
2019-06-08 04:49:28 +02:00
install_dialog() {
if [ ! "$(which dialog 2> /dev/null)" ]; then
2021-01-25 16:54:41 +01:00
prompt -w "\n 'dialog' need to be installed for this shell"
install_program "dialog"
2019-06-08 04:49:28 +02:00
fi
}
remove() {
2021-01-25 16:54:41 +01:00
local theme=${1}
2020-11-10 12:46:53 +01:00
# Check for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then
2023-04-15 17:05:00 +02:00
prompt -i "Checking for the existence of themes directory..."
2021-01-25 16:54:41 +01:00
if [[ -d "${THEME_DIR}/${theme}" ]]; then
2023-04-15 17:05:00 +02:00
prompt -i "\n Find installed theme: '${THEME_DIR}/${theme}'..."
2021-01-25 16:54:41 +01:00
rm -rf "${THEME_DIR}/${theme}"
2022-10-30 16:36:05 +01:00
prompt -w "\n Removed: '${THEME_DIR}/${theme}'..."
2022-10-30 16:20:45 +01:00
elif [[ -d "/boot/grub/themes/${theme}" ]]; then
2023-04-15 17:05:00 +02:00
prompt -i "\n Find installed theme: '/boot/grub/themes/${theme}'..."
2022-10-30 16:20:45 +01:00
rm -rf "/boot/grub/themes/${theme}"
prompt -w "\n Removed: '/boot/grub/themes/${theme}'..."
elif [[ -d "/boot/grub2/themes/${theme}" ]]; then
2023-04-15 17:05:00 +02:00
prompt -i "\n Find installed theme: '/boot/grub2/themes/${theme}'..."
2022-10-30 16:20:45 +01:00
rm -rf "/boot/grub2/themes/${theme}"
prompt -w "\n Removed: '/boot/grub2/themes/${theme}'..."
else
prompt -e "\n Specified ${theme} theme does not exist!"
exit 0
fi
local grub_config_location=""
2023-04-15 17:05:00 +02:00
if [[ -f "/etc/default/grub" ]]; then
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
2023-04-15 17:05:00 +02:00
prompt -e "\n Cannot find grub config file in default locations!"
prompt -w "\n Please inform the developers by opening an issue on github."
prompt -i "\n Exiting..."
exit 1
2021-01-25 09:49:21 +01:00
fi
local current_theme="" # Declaration and assignment should be done seperately ==> https://github.com/koalaman/shellcheck/wiki/SC2155
2023-04-15 17:05:00 +02:00
current_theme="$(grep 'GRUB_THEME=' $grub_config_location | grep -v \#)"
2023-04-15 17:05:00 +02:00
if [[ -n "$current_theme" ]]; then
# 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"
2023-04-15 17:05:00 +02:00
if [[ -f "$grub_config_location".back ]]; then
rm -rf "$grub_config_location".back
fi
# Update grub config
2023-04-15 17:05:00 +02:00
prompt -i "\n Resetting grub theme...\n"
updating_grub
else
2023-04-15 17:05:00 +02:00
prompt -e "\n No active theme found."
prompt -i "\n Exiting..."
exit 1
fi
else
#Check if password is cached (if cache timestamp not expired yet)
if sudo -n true 2> /dev/null && echo; then
#No need to ask for password
2022-10-30 16:20:45 +01:00
sudo "$0" -t ${theme} "${PROG_ARGS[@]}"
else
#Ask for password
prompt -e "\n [ Error! ] -> Run me as root! "
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
if sudo -S echo <<< $REPLY 2> /dev/null && echo; then
#Correct password, use with sudo's stdin
2022-10-30 16:20:45 +01:00
sudo -S "$0" -t ${theme} "${PROG_ARGS[@]}" <<< $REPLY
else
#block for 3 seconds before allowing another attempt
sleep 3
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi
fi
fi
}
2021-06-15 07:19:28 +02:00
dialog_installer() {
if [[ ! -x /usr/bin/dialog ]]; then
if [[ $UID -ne $ROOT_UID ]]; then
#Check if password is cached (if cache timestamp not expired yet)
2019-06-08 04:49:28 +02:00
if sudo -n true 2> /dev/null && echo; then
2021-06-15 07:19:28 +02:00
#No need to ask for password
exec sudo $0
else
#Ask for password
prompt -e "\n [ Error! ] -> Run me as root! "
read -r -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
if sudo -S echo <<< $REPLY 2> /dev/null && echo; then
2021-06-15 07:19:28 +02:00
#Correct password, use with sudo's stdin
sudo $0 <<< $REPLY
else
#block for 3 seconds before allowing another attempt
sleep 3
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi
fi
fi
2021-06-15 07:19:28 +02:00
install_dialog
fi
2021-06-15 07:19:28 +02:00
run_dialog
install "${theme}" "${icon}" "${screen}"
2022-03-19 03:32:20 +01:00
exit 1
2021-06-15 07:19:28 +02:00
}
2019-06-08 04:49:28 +02:00
2022-01-22 11:29:10 +01:00
#######################################################
# :::::: A R G U M E N T H A N D L I N G :::::: #
#######################################################
2022-02-21 04:26:29 +01:00
install=install
2022-03-19 03:32:20 +01:00
2021-01-25 16:54:41 +01:00
while [[ $# -gt 0 ]]; do
PROG_ARGS+=("${1}")
2021-06-15 07:19:28 +02:00
dialog='false'
2019-06-08 04:49:28 +02:00
case "${1}" in
2021-01-25 16:54:41 +01:00
-r|--remove)
remove='true'
2022-10-30 16:36:05 +01:00
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
;;
whitesur)
themes+=("${THEME_VARIANTS[3]}")
shift
;;
-*)
break
;;
*)
prompt -e "ERROR: Unrecognized theme variant '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
done
2020-05-19 17:40:47 +02:00
;;
2022-02-21 04:26:29 +01:00
-g|--generate)
shift 1
THEME_DIR="${1}"
install=generate
shift 1
;;
2022-10-30 16:20:45 +01:00
-b|--boot)
install_boot='true'
shift 1
;;
2021-01-25 16:54:41 +01:00
-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
;;
whitesur)
2021-12-05 07:12:59 +01:00
themes+=("${THEME_VARIANTS[3]}")
2021-01-25 16:54:41 +01:00
shift
;;
2022-03-19 03:32:20 +01:00
-*)
2021-01-25 16:54:41 +01:00
break
;;
*)
prompt -e "ERROR: Unrecognized theme variant '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
done
2021-01-07 23:28:48 +01:00
;;
2021-01-25 16:54:41 +01:00
-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
;;
-*)
2021-01-25 16:54:41 +01:00
break
;;
*)
prompt -e "ERROR: Unrecognized icon variant '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
done
;;
2021-01-25 16:54:41 +01:00
-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
;;
-*)
2021-01-25 16:54:41 +01:00
break
;;
*)
2024-05-16 07:29:13 +02:00
prompt -e "ERROR: Unrecognized screen variant '$1'."
2021-01-25 16:54:41 +01:00
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
done
;;
2019-06-08 04:49:28 +02:00
-h|--help)
usage
exit 0
;;
*)
2021-01-25 16:54:41 +01:00
prompt -e "ERROR: Unrecognized installation option '$1'."
prompt -i "Try '$0 --help' for more information."
2019-06-08 04:49:28 +02:00
exit 1
;;
esac
2019-05-31 09:15:27 +02:00
done
2022-01-22 11:29:10 +01:00
#############################
# :::::: M A I N :::::: #
#############################
2021-06-02 07:15:05 +02:00
# Show terminal user interface for better use
2021-06-15 07:19:28 +02:00
if [[ "${dialog:-}" == 'false' ]]; then
2021-06-02 07:15:05 +02:00
if [[ "${remove:-}" != 'true' ]]; then
for theme in "${themes[@]-${THEME_VARIANTS[0]}}"; do
for icon in "${icons[@]-${ICON_VARIANTS[0]}}"; do
for screen in "${screens[@]-${SCREEN_VARIANTS[0]}}"; do
2022-02-21 04:26:29 +01:00
$install "${theme}" "${icon}" "${screen}"
2021-06-02 07:15:05 +02:00
done
2021-01-25 16:54:41 +01:00
done
done
2021-06-02 07:15:05 +02:00
elif [[ "${remove:-}" == 'true' ]]; then
for theme in "${themes[@]-${THEME_VARIANTS[0]}}"; do
remove "${theme}"
done
fi
2021-06-15 07:19:28 +02:00
else
dialog_installer
fi
2019-06-08 04:49:28 +02:00
2022-02-21 05:00:36 +01:00
exit 0