Skip to content

Instantly share code, notes, and snippets.

@otzoran
Last active October 1, 2021 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otzoran/0214f5f9e817c54c597da31dd86c9162 to your computer and use it in GitHub Desktop.
Save otzoran/0214f5f9e817c54c597da31dd86c9162 to your computer and use it in GitHub Desktop.
Automate brew update
#!/usr/bin/env bash
# curl -o xx https://gist.githubusercontent.com/otzoran/0214f5f9e817c54c597da31dd86c9162/raw
TIM=60
PROG=$(basename $0)
trap 'echo "ERROR $? at ${PROG}:$LINENO - [$BASH_COMMAND]"' err
function wait_confirmation
{
set +e # without it, timeout will provoke exit from the shell...
casks="$1"
ANS=''
for ii in seq 1 5; do
# play sound brew_end_fetch.m4a
#set -x
/usr/bin/afplay -v 0.3 ~/Music/brew_end_fetch.m4a
read -t $TIM -p "Finished brew fetch $casks. Install? [y]: " ANS
exstat=$?
if [[ $exstat > 128 ]]; then
HHMM=$(date '+%T')
printf "\n%2d [%s] timeout\n" $ii $HHMM
continue
elif [[ $exstat == 0 ]]; then
[[ -z $ANS ]] && ANS="y";
else
printf "%2d in loop, read exstat == $exstat\n"
fi
if [[ $ANS == "y" ]]; then
return 0
fi
done
set +e
return 1
}
set -ex
trap -p
brew update
fm=$(brew outdated --formula)
fm=${fm//$'\n'/ } # suppress \n replace by space
set +x
#ck=$(brew outdated --cask)
printf "\n=====\n"
if [[ -n "$fm" ]]; then
/usr/bin/afplay -v 0.3 ~/Music/brew_start_upg_formula.m4a
brew upgrade --formula
fi
set -x
pkk=$(brew outdated --cask --greedy --quiet | grep -v android-file-transfer | paste -s -d ' ' -)
pkk=${pkk//$'\n'/ } # suppress \n replace by space
set +x
#test pkk='opera postman'
#TODO: brew info $pkg, ==> Artifacts
# Brave Browser.app (App)
# pgrep -f "Brave Browser.app" => list of pid's, one per line {pgrep -fl = long}
if [[ -n "$pkk" ]]; then
printf "fetch outdated:\n$pkk\n"
brew fetch --cask $pkk
wait_confirmation "$pkk"
if [[ $? == 0 ]]; then
printf "installing: $pkk\n"
# 2021-01 upd switch
brew reinstall --cask $pkk
else
printf "Bailed out, run brew reinstall --cask $pkk"
fi
fi
printf "\n===== updated formula:\n$fm\n"
printf "\n===== updated casks:\n$pkk\n"
@otzoran
Copy link
Author

otzoran commented Oct 1, 2021

added trap

@otzoran
Copy link
Author

otzoran commented Oct 1, 2021

add curl to download it => xx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment