dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 6e034e4c2ea1f5fa366c8a3bf485d9d731c4bf16
parent 9e28f40c19a8affb09af473c4abef246cba41d4c
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Tue, 23 Jul 2019 14:06:44 +0200

updatemaster: fix sudo caching

Former-commit-id: 3d2c909a4314b568f95c79260ac23be364818c75
Diffstat:
Mscripts/updatemaster | 24++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/scripts/updatemaster b/scripts/updatemaster @@ -25,16 +25,26 @@ hr() { cols=$(tput cols) printf '#%.0s' $(seq 1 "$cols") } +clean_up() { + kill $cache_sudo_pid + exit ${1:-0} +} -renew_sudo() { - if ! sudo --non-interactive 2> /dev/null; then - echo "Extend sudo timeout by giving your password now." - fi - sudo --validate +cache_sudo() { + while :; do + sudo -n true + sleep 60 + kill -0 "$$" || clean_up + done 2>/dev/null } # }}} echo_progress "### STARTING UPDATE SCRIPT ###\n" +echo "Please enter the administrator password (required for installation/upgrading)." +sudo -v +cache_sudo & +cache_sudo_pid=$! +trap clean_up SIGINT SIGKILL SIGQUIT SIGTERM # Parse options/arguments {{{ while getopts "hfcns" opt; do @@ -64,7 +74,7 @@ while getopts "hfcns" opt; do echo "Options can be combined. For example:" echo " updatemaster -fs" echo "Would update all formulas, and ask you to select which casks to upgrade." - exit 0 + clean_up ;; esac done @@ -121,7 +131,6 @@ if command -v brew &> /dev/null; then elif [ $select_casks = 1 ]; then read -rp "Casks to upgrade (empty string cancels upgrade): " -a CASKS; for i in ${CASKS[@]}; do - renew_sudo if ! brew cask upgrade "$i"; then echo -e "Could not upgrade cask $i."; fi done else @@ -133,7 +142,6 @@ if command -v brew &> /dev/null; then echo read -rp "Which casks would you like to upgrade? " -a CASKS; for i in "${CASKS[@]}"; do - renew_sudo if ! brew cask upgrade "$i"; then echo -e "Could not upgrade cask $i."; fi done ;;