From d005d49168598ad12d54faa27e0bcedd0b68e45d Mon Sep 17 00:00:00 2001 From: Nurverek Date: Tue, 10 Nov 2020 15:16:53 +0330 Subject: [PATCH 1/3] Few grammatical error fixed --- install.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index b2bae0e..50b152c 100755 --- a/install.sh +++ b/install.sh @@ -43,7 +43,7 @@ prompt () { esac } -# Check command avalibility +# Check command availability function has_command() { command -v $1 > /dev/null } @@ -108,7 +108,7 @@ install() { local icon="color" fi - # Checking 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 clear @@ -123,7 +123,7 @@ install() { fi fi - # Create themes directory if not exists + # Create themes directory if it didn't exist echo -e "\n Checking for the existence of themes directory..." [[ -d "${THEME_DIR}/${name}" ]] && rm -rf "${THEME_DIR}/${name}" @@ -170,7 +170,7 @@ install() { echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub fi - # Make sure set the right resolution for grub + # Make sure the right resolution for grub is set if [[ ${screen} == '1080p' ]]; then gfxmode="GRUB_GFXMODE=1920x1080,auto" elif [[ ${screen} == '1080p_21:9' ]]; then @@ -208,7 +208,7 @@ install() { # Error message prompt -e "\n [ Error! ] -> Run me as root! " - # persisted execution of the script as root + # Persistent execution of the script as root if [[ -n ${tui_root_login} ]] ; then if [[ -n "${theme}" && -n "${screen}" ]]; then sudo -S <<< ${tui_root_login} $0 --${theme} --${icon} --${screen} @@ -333,7 +333,7 @@ remove() { exit 0 fi - # Checking 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 echo -e "\n Checking for the existence of themes directory..." if [[ -d "${THEME_DIR}/${name}" ]]; then @@ -359,7 +359,7 @@ remove() { # Error message prompt -e "\n [ Error! ] -> Run me as root " - # persisted execution of the script as root + # Persistent execution of the script as root read -p "[ trusted ] specify the root password : " -t${MAX_DELAY} -s [[ -n "$REPLY" ]] && { if [[ -n "${theme}" ]]; then @@ -371,7 +371,7 @@ remove() { fi } -# show terminal user interface for better use +# Show terminal user interface for better use if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ -x /usr/bin/dialog ]] ; then run_dialog fi From f4b1a85ab003ac77c7a278a937c2ab70df9bdb52 Mon Sep 17 00:00:00 2001 From: Nurverek Date: Tue, 10 Nov 2020 16:04:12 +0330 Subject: [PATCH 2/3] - Reordered the $screen check function in pre-root part of install() to avoid unnecessary code execution in case the program exists early due to $screen error if ultrawide is selected with Slazy - Minor grammatical error fixes --- install.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 50b152c..49c844b 100755 --- a/install.sh +++ b/install.sh @@ -26,7 +26,7 @@ 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 +# echo like ... with flag type and display message colors prompt () { case ${1} in "-s"|"--success") @@ -91,17 +91,17 @@ install() { local screen="1080p" fi + if [[ ${screen} == '1080p_21:9' && ${name} == 'Slaze' ]]; then + prompt -e "ultrawide 1080p 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 [[ ${screen} == '1080p_21:9' && ${name} == 'Slaze' ]]; then - prompt -e "ultrawide 1080p does not support Slaze theme" - exit 1 - fi - if [[ ${icon} == 'white' ]]; then local icon="white" else @@ -110,6 +110,7 @@ install() { # Check for root access and proceed if it is present if [ "$UID" -eq "$ROOT_UID" ]; then + clear if [[ "${custom_background}" == "custom-background" ]]; then @@ -214,7 +215,7 @@ install() { sudo -S <<< ${tui_root_login} $0 --${theme} --${icon} --${screen} fi else - read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s + read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s [[ -n "$REPLY" ]] && { if [[ -n "${theme}" && -n "${screen}" ]]; then sudo -S <<< $REPLY "$0" --${theme} --${icon} --${screen} From aa8108f74b3e6488523cae695a69a91e14a3048b Mon Sep 17 00:00:00 2001 From: Nurverek Date: Tue, 10 Nov 2020 21:48:52 +0330 Subject: [PATCH 3/3] [install.sh] Fixed the following issues : - The password prompt went all wonky if password was wrong - The password prompt did not use system password cache and kept asking for password again on reruns of script - Installation failed if the script was initially ran by "sudo" due to inability to preserve ownership of files during cp commands - Security issue where the password prompt could be interrupted (Ctrl+C) and rerun without sleeping for few seconds first just like normal sudo failure in terminal - The sudo command would no longer accept password from ANY commands system-wide if wrong password was given to the install script enough times!! (the only fix would be restarting the system) --- install.sh | 165 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 110 insertions(+), 55 deletions(-) diff --git a/install.sh b/install.sh index 49c844b..2e16e87 100755 --- a/install.sh +++ b/install.sh @@ -110,7 +110,6 @@ install() { # Check for root access and proceed if it is present if [ "$UID" -eq "$ROOT_UID" ]; then - clear if [[ "${custom_background}" == "custom-background" ]]; then @@ -133,28 +132,29 @@ install() { # Copy theme prompt -i "\n Installing ${name} ${icon} ${screen} theme..." - cp -a "${REO_DIR}/common/"{*.png,*.pf2} "${THEME_DIR}/${name}" - cp -a "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${name}/theme.txt" + # 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" 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" + 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 "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${name}/background.jpg" + cp -a --no-preserve=ownership "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${name}/background.jpg" 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}" + 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}" 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}" + 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}" fi # Set theme @@ -206,41 +206,71 @@ install() { updating_grub prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' " else - # Error message - prompt -e "\n [ Error! ] -> Run me as root! " + #Check if password is cached (if cache timestamp not expired yet) + sudo -n true 2> /dev/null && echo + + if [[ $? == 0 ]]; then + #No need to ask for password + sudo "$0" --${theme} --${icon} --${screen} - # Persistent execution of the script as root - if [[ -n ${tui_root_login} ]] ; then - if [[ -n "${theme}" && -n "${screen}" ]]; then - sudo -S <<< ${tui_root_login} $0 --${theme} --${icon} --${screen} - fi else - read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s - [[ -n "$REPLY" ]] && { - if [[ -n "${theme}" && -n "${screen}" ]]; then - sudo -S <<< $REPLY "$0" --${theme} --${icon} --${screen} - fi - } || { - operation_canceled - } - fi + #Ask for password + if [[ -n ${tui_root_login} ]] ; then + if [[ -n "${theme}" && -n "${screen}" ]]; then + sudo -S $0 --${theme} --${icon} --${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} + else + #block for 3 seconds before allowing another attempt + sleep 3 + prompt -e "\n [ Error! ] -> Incorrect password!\n" + exit 1 + fi + fi + fi fi } run_dialog() { if [[ -x /usr/bin/dialog ]]; then - tui_root_login=$(dialog --backtitle ${Project_Name} \ - --title "ROOT LOGIN" \ - --insecure \ - --passwordbox "require root permission" 8 50 \ - --output-fd 1 ) - [[ -z ${tui_root_login} ]] && exit ${UID} - sudo -S <<< $tui_root_login $0 - test $? -eq 0 || { - prompt -e "\n [ Error! ] -> wrong passwords" - exit 1 - } + if [[ "$UID" -ne "$ROOT_UID" ]]; then + #Check if password is cached (if cache timestamp not expired yet) + sudo -n true 2> /dev/null && echo + + if [[ $? == 0 ]]; 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 ) + + sudo -S echo <<< $tui_root_login 2> /dev/null && echo + + if [[ $? == 0 ]]; 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 + clear + prompt -e "\n [ Error! ] -> Incorrect password!\n" + exit 1 + fi + fi + fi tui=$(dialog --backtitle ${Project_Name} \ --radiolist "Choose your Grub theme : " 15 40 5 \ @@ -357,18 +387,30 @@ remove() { updating_grub else - # Error message - prompt -e "\n [ Error! ] -> Run me as root " + #Check if password is cached (if cache timestamp not expired yet) + sudo -n true 2> /dev/null && echo - # Persistent 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[@]}" + if [[ $? == 0 ]]; then + #No need to ask for password + sudo "$0" "${PROG_ARGS[@]}" + else + #Ask for password + 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" "${PROG_ARGS[@]}" <<< $REPLY + else + #block for 3 seconds before allowing another attempt + sleep 3 + clear + prompt -e "\n [ Error! ] -> Incorrect password!\n" + exit 1 fi - } || { - operation_canceled - } + fi fi } @@ -378,16 +420,29 @@ if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ -x /usr/bin/dialog ]] ; then fi if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ ! -x /usr/bin/dialog ]] ; then - # Error message - prompt -e "\n [ Error! ] -> Run me as root! " + #Check if password is cached (if cache timestamp not expired yet) + sudo -n true 2> /dev/null && echo - # persisted execution of the script as root - read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s - [[ -n "$REPLY" ]]&& { - exec sudo -S <<< $REPLY $0 - }|| { - operation_canceled - } + if [[ $? == 0 ]]; then + #No need to ask for password + exec sudo $0 + else + #Ask for password + 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 $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 while [[ $# -ge 1 ]]; do