Merge pull request #18 from Jukoo/grupdate

Grub theme :  ⬆️ install.sh update and README file
This commit is contained in:
Vince 2019-06-08 09:15:39 +08:00 committed by GitHub
commit 7ded5467a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 123 additions and 42 deletions

View File

@ -1,11 +1,19 @@
```
____ ____ _ _ ____ ____ _____ _ _ _____ __ __ _____ ____
/ ___| _ \| | | | __ )___ \ |_ _| | | | ____| \/ | ____/ ___|
| | _| |_) | | | | _ \ __) | | | | |_| | _| | |\/| | _| \___ \
| |_| | _ <| |_| | |_) / __/ | | | _ | |___| | | | |___ ___) |
\____|_| \_\\___/|____/_____| |_| |_| |_|_____|_| |_|_____|____/
## Grub2 Themes ```
Flat Design themes for Grub2. ##Flat Design themes for Grub2.
## Install ## Install
Usage: `sudo ./install.sh` **[OPTIONS...]** Usage: `sudo ./install.sh` **[OPTIONS...]**
*if no option used the terminal user interface will be show up*
| OPTIONS: | | | OPTIONS: | |
|:---------------|:-------------| |:---------------|:-------------|

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# Grub2 Dark Theme # Grub2 Dark Theme
ROOT_UID=0 ROOT_UID=0
THEME_DIR="/boot/grub/themes" THEME_DIR="/boot/grub/themes"
@ -8,13 +9,56 @@ THEME_DIR_2="/boot/grub2/themes"
REO_DIR=$(cd $(dirname $0) && pwd) REO_DIR=$(cd $(dirname $0) && pwd)
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
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
}
# print "GRUB THEME" whene the script is launched
ascii_art_header () {
[[ -f README.md ]] && {
header_title=$(sed -n 2,8p README.md)
prompt -i "$header_title"
}
}
#ascii_art_header # uncomment this line to show Grub theme ascii art
# Check command avalibility # Check command avalibility
function has_command() { function has_command() {
command -v $1 > /dev/null command -v $1 > /dev/null
} }
usage() { usage() {
printf "%s\n" "Usage: $0 [OPTIONS...]" printf "%s\n" "Usage: ${0##*/} [OPTIONS...]"
printf "\n%s\n" "OPTIONS:" printf "\n%s\n" "OPTIONS:"
printf " %-25s%s\n" "-l, --slaze" "slaze grub theme" printf " %-25s%s\n" "-l, --slaze" "slaze grub theme"
printf " %-25s%s\n" "-s, --stylish" "stylish grub theme" printf " %-25s%s\n" "-s, --stylish" "stylish grub theme"
@ -24,6 +68,7 @@ usage() {
} }
install() { install() {
if [[ ${theme} == 'slaze' ]]; then if [[ ${theme} == 'slaze' ]]; then
local name="Slaze" local name="Slaze"
elif [[ ${theme} == 'stylish' ]]; then elif [[ ${theme} == 'stylish' ]]; then
@ -35,8 +80,9 @@ install() {
else else
echo -e "\n Please run ./install.sh with option, run ./install.sh -h for help!" echo -e "\n Please run ./install.sh with option, run ./install.sh -h for help!"
exit 0 exit 0
fi fi
# Checking for root access and proceed if it is present # Checking for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then if [ "$UID" -eq "$ROOT_UID" ]; then
@ -48,7 +94,7 @@ install() {
[[ -d /boot/grub2 ]] && mkdir -p ${THEME_DIR_2}/${name} [[ -d /boot/grub2 ]] && mkdir -p ${THEME_DIR_2}/${name}
# Copy theme # Copy theme
echo -e "\n Installing ${name} theme..." prompt -i "Installing ${name} theme..."
if [ -d /boot/grub ]; then if [ -d /boot/grub ]; then
cp -a ${REO_DIR}/common/* ${THEME_DIR}/${name} cp -a ${REO_DIR}/common/* ${THEME_DIR}/${name}
@ -77,16 +123,16 @@ install() {
fi fi
# Set theme # Set theme
echo -e "\n Setting ${name} as default..." prompt -i "Setting ${name} as default..."
grep "GRUB_THEME=" /etc/default/grub 2>&1 >/dev/null && sed -i '/GRUB_THEME=/d' /etc/default/grub grep "GRUB_THEME=" /etc/default/grub 2>&1 >/dev/null && sed -i '/GRUB_THEME=/d' /etc/default/grub
[[ -d /boot/grub ]] && echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub [[ -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 [[ -d /boot/grub2 ]] && echo "GRUB_THEME=\"${THEME_DIR_2}/${name}/theme.txt\"" >> /etc/default/grub
# Update grub config # Update grub config
echo -e "\n Updating grub config..." prompt -i "Updating grub config..."
if has_command update-grub; then if has_command update-grub; then
update-grub update-grub
elif has_command grub-mkconfig; then elif has_command grub-mkconfig; then
grub-mkconfig -o /boot/grub/grub.cfg grub-mkconfig -o /boot/grub/grub.cfg
elif has_command grub2-mkconfig; then elif has_command grub2-mkconfig; then
@ -94,42 +140,69 @@ install() {
fi fi
# Success message # Success message
echo -e "\n All done! " prompt -s "All done!"
else else
# Error message # Error message
echo -e "\n Error! -> Run me as root " prompt -e "\n[ E r r o r ] -> 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 --${theme}
fi
}|| {
prompt "\n Operation canceled Bye"
exit 1
}
fi fi
} }
while [[ $# -gt 0 ]]; do # show terminal user interface for better use
case "${1}" in if [[ $# -lt 1 ]] ;then
-l|--slaze) if [[ -x /usr/bin/dialog ]] ; then
theme='slaze' tui=$(dialog --backtitle "Grub 2 Themes" \
shift 1 --radiolist "Choose your Grub theme : " 15 40 5 \
;; 1 "Slaze Theme" off \
-s|--stylish) 2 "Stylish Theme" on \
theme='stylish' 3 "Tela Theme" off \
shift 1 4 "Vimix Theme" off --output-fd 1 )
;; case "$tui" in
-t|--tela) 1) theme="slaze" ;;
theme='tela' 2) theme="stylish" ;;
shift 1 3) theme="tela" ;;
;; 4) theme="vimix" ;;
-v|--vimix) *) prompt "Canceled" ;;
theme='vimix' esac
shift 1
;; fi
-h|--help) fi
usage while [[ $# -ge 1 ]]; do
exit 0 case "${1}" in
;; -l|--slaze)
*) theme='slaze'
echo "ERROR: Unrecognized installation option '$1'." ;;
echo "Try '$0 --help' for more information." -s|--stylish)
exit 1 theme='stylish'
;; ;;
esac -t|--tela)
theme='tela'
;;
-v|--vimix)
theme='vimix'
;;
-h|--help)
usage
exit 0
;;
*)
prompt -e "ERROR: Unrecognized installation option '$1'."
prompt -i "Try '$0 --help' for more information."
exit 1
;;
esac
shift
done done
install install