grub2-themes/install.sh

444 lines
13 KiB
Bash
Raw Normal View History

2019-05-31 09:15:27 +02:00
#!/bin/bash
2019-10-23 14:32:32 +02:00
# Grub2 Themes
2020-02-23 01:31:37 +01:00
set -o errexit
2019-05-31 09:15:27 +02:00
2020-02-23 01:31:37 +01:00
[ 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=
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)"
2020-02-23 01:31:37 +01:00
}
2019-06-08 04:49:28 +02:00
#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:"
printf " %-25s%s\n" "-b, --boot" "install grub theme into /boot/grub/themes"
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-12-05 10:55:00 +01:00
printf " %-25s%s\n" "-w, --white" "Install white icon version"
2020-05-19 17:40:47 +02:00
printf " %-25s%s\n" "-u, --ultrawide" "Install 2560x1080 background image - not available for slaze grub theme"
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"
2020-01-27 09:16:40 +01:00
printf " %-25s%s\n" "-4, --4k" "Install 4k(3840x2160) background image"
printf " %-25s%s\n" "-r, --remove" "Remove theme (must add theme name option)"
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
prompt -i "\n Run ./install.sh -h for help or install dialog"
install_dialog
prompt -i "\n Run ./install.sh again!"
2019-05-31 09:51:14 +02:00
exit 0
2019-06-08 04:49:28 +02:00
fi
if [[ ${screen} == '2k' ]]; then
local screen="2k"
elif [[ ${screen} == '4k' ]]; then
local screen="4k"
2020-05-19 17:40:47 +02:00
elif [[ ${screen} == '1080p_21:9' ]]; then
local screen="1080p_21:9"
else
local screen="1080p"
fi
if [[ ${custom_background} == 'custom-background' ]]; then
local custom_background="custom-background"
else
local custom_background="default-background"
fi
2020-05-19 17:40:47 +02:00
if [[ ${screen} == '1080p_21:9' && ${name} == 'Slaze' ]]; then
prompt -e "ultrawide 1080p does not support Slaze theme"
exit 1
fi
2019-12-05 10:55:00 +01:00
if [[ ${icon} == 'white' ]]; then
local icon="white"
else
local icon="color"
2020-05-29 16:16:59 +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
clear
2019-05-31 09:51:14 +02:00
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
2019-05-31 09:51:14 +02:00
# 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}"
2019-10-23 14:32:32 +02:00
mkdir -p "${THEME_DIR}/${name}"
2019-05-31 09:51:14 +02:00
# Copy theme
2020-05-19 17:40:47 +02:00
prompt -i "\n Installing ${name} ${icon} ${screen} theme..."
2019-05-31 09:51:14 +02:00
2020-06-20 16:53:17 +02:00
cp -a "${REO_DIR}/common/"{*.png,*.pf2} "${THEME_DIR}/${name}"
2019-12-05 10:57:41 +01:00
cp -a "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${name}/theme.txt"
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 "${REO_DIR}/${custom_background}" "${THEME_DIR}/${name}/background.jpg"
2020-10-17 16:07:46 +02:00
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
2020-05-19 17:40:47 +02:00
else
cp -a "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${name}/background.jpg"
2020-10-17 14:25:21 +02:00
fi
if [[ ${screen} == '1080p_21:9' ]]; then
cp -a "${REO_DIR}/assets/assets-${icon}/icons-1080p" "${THEME_DIR}/${name}/icons"
cp -a "${REO_DIR}/assets/assets-${icon}/select-1080p/"*.png "${THEME_DIR}/${name}"
else
cp -a "${REO_DIR}/assets/assets-${icon}/icons-${screen}" "${THEME_DIR}/${name}/icons"
cp -a "${REO_DIR}/assets/assets-${icon}/select-${screen}/"*.png "${THEME_DIR}/${name}"
2020-05-19 17:40:47 +02:00
fi
2019-05-31 09:15:27 +02:00
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
2019-08-30 03:55:07 +02:00
# 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
else
#Append GRUB_THEME
echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub
fi
2020-01-08 11:53:36 +01:00
# Make sure set the right resolution for grub
2020-05-04 07:07:19 +02:00
if [[ ${screen} == '1080p' ]]; then
gfxmode="GRUB_GFXMODE=1920x1080,auto"
2020-05-19 17:40:47 +02:00
elif [[ ${screen} == '1080p_21:9' ]]; 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"
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
# Update grub config
2020-05-04 07:07:19 +02:00
prompt -i "\n Updating grub config...\n"
2019-06-08 04:49:28 +02:00
updating_grub
else
2020-02-03 12:31:44 +01:00
# Error message
prompt -e "\n [ Error! ] -> Run me as root! "
# persisted execution of the script as root
2020-02-23 01:31:37 +01:00
if [[ -n ${tui_root_login} ]] ; then
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S <<< ${tui_root_login} $0 --${theme} --${icon} --${screen} --${custom_background}
2020-02-23 01:31:37 +01:00
fi
else
2020-02-23 01:31:37 +01:00
read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s
[[ -n "$REPLY" ]] && {
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S <<< $REPLY "$0" "${PROG_ARGS[@]}"
2020-02-23 01:31:37 +01:00
fi
} || {
operation_canceled
}
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
2020-02-23 01:31:37 +01:00
tui_root_login=$(dialog --backtitle ${Project_Name} \
--title "ROOT LOGIN" \
--insecure \
2020-05-29 16:16:59 +02:00
--passwordbox "require root permission" 8 50 \
2020-02-23 01:31:37 +01:00
--output-fd 1 )
2020-05-29 16:16:59 +02:00
[[ -z ${tui_root_login} ]] && exit ${UID}
sudo -S <<< $tui_root_login $0
test $? -eq 0 || {
2020-02-23 01:31:37 +01:00
prompt -e "\n [ Error! ] -> wrong passwords"
2020-05-29 16:16:59 +02:00
exit 1
2020-02-23 01:31:37 +01:00
}
2020-08-24 12:36:25 +02:00
2020-02-23 01:31:37 +01:00
tui=$(dialog --backtitle ${Project_Name} \
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" ;;
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 \
2 "color" on --output-fd 1 )
case "$tui" in
1) icon="white" ;;
2) icon="color" ;;
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 \
4 "4k (3840x2160)" off --output-fd 1 )
2019-10-23 14:32:32 +02:00
case "$tui" in
1) screen="1080p" ;;
2020-05-19 17:40:47 +02:00
2) screen="1080p_21:9" ;;
3) screen="2k" ;;
4) screen="4k" ;;
2020-01-25 17:24:33 +01:00
*) operation_canceled ;;
2019-10-23 14:32:32 +02:00
esac
2019-06-08 04:49:28 +02:00
fi
}
2020-01-25 17:24:33 +01:00
operation_canceled() {
clear
2020-02-03 12:31:44 +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
elif 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
# Success message
prompt -s "\n * All done!"
prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' "
}
2019-06-08 04:49:28 +02:00
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
2019-10-28 07:45:19 +01:00
elif has_command apt-get; then
2019-06-08 04:49:28 +02:00
sudo apt-get install dialog
2019-10-28 07:45:19 +01:00
elif has_command dnf; then
2019-11-06 09:16:27 +01:00
sudo dnf install -y dialog
2019-10-28 07:45:19 +01:00
elif has_command yum; then
2019-06-08 04:49:28 +02:00
sudo yum install dialog
2019-10-28 07:45:19 +01:00
elif has_command pacman; then
2019-06-08 04:49:28 +02:00
sudo pacman -S --noconfirm dialog
fi
fi
}
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
# Checking 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}"
else
prompt -i "\n ${name} grub theme not exist!"
exit 0
fi
# Backup grub config
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!"
exit 0
fi
# Update grub config
prompt -i "\n Resetting grub theme...\n"
updating_grub
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" ]] && {
if [[ -n "${theme}" ]]; then
sudo -S <<< $REPLY "$0" "${PROG_ARGS[@]}"
fi
} || {
2020-01-25 17:24:33 +01:00
operation_canceled
}
fi
}
2019-06-08 04:49:28 +02:00
# show terminal user interface for better use
2020-02-23 01:31:37 +01:00
if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ -x /usr/bin/dialog ]] ; then
2019-06-08 04:49:28 +02:00
run_dialog
fi
2020-02-23 01:31:37 +01:00
if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ ! -x /usr/bin/dialog ]] ; then
2019-06-08 04:54:13 +02:00
# Error message
2020-02-03 12:31:44 +01:00
prompt -e "\n [ Error! ] -> Run me as root! "
2019-06-08 04:54:13 +02:00
# persisted execution of the script as root
2020-02-03 12:31:44 +01:00
read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s
2019-06-08 04:54:13 +02:00
[[ -n "$REPLY" ]]&& {
2019-06-08 14:43:35 +02:00
exec sudo -S <<< $REPLY $0
2019-06-08 04:54:13 +02:00
}|| {
2020-01-25 17:24:33 +01:00
operation_canceled
2019-06-08 04:54:13 +02:00
}
2019-06-08 04:49:28 +02:00
fi
while [[ $# -ge 1 ]]; do
PROG_ARGS+=("${1}")
2019-06-08 04:49:28 +02:00
case "${1}" in
-b|--boot)
THEME_DIR="/boot/grub/themes"
;;
2019-06-08 04:49:28 +02:00
-l|--slaze)
theme='slaze'
;;
-s|--stylish)
theme='stylish'
;;
-t|--tela)
theme='tela'
;;
-v|--vimix)
theme='vimix'
;;
2019-12-05 10:55:00 +01:00
-w|--white)
icon='white'
;;
-c|--color)
icon='color'
;;
-1|--1080p)
screen='1080p'
;;
-2|--2k)
screen='2k'
;;
-4|--4k)
screen='4k'
;;
2020-05-19 17:40:47 +02:00
-u|--ultrawide|--1080p_21:9)
screen='1080p_21:9'
;;
-C|--custom-background|--custom)
custom_background='custom-background'
;;
-r|--remove)
remove='true'
;;
2019-06-08 04:49:28 +02:00
-h|--help)
usage
exit 0
;;
*)
prompt -e "\n ERROR: Unrecognized installation option '$1'."
2020-01-25 18:22:00 +01:00
prompt -i "Try '$0 --help' for more information."
2019-06-08 04:49:28 +02:00
exit 1
;;
esac
shift
2019-05-31 09:15:27 +02:00
done
if [[ "${remove:-}" != 'true' ]]; then
install
2020-01-27 09:16:40 +01:00
elif [[ "${remove:-}" == 'true' ]]; then
remove
fi
2019-06-08 04:49:28 +02:00
exit 0