Last active
October 1, 2021 11:30
-
-
Save otzoran/0214f5f9e817c54c597da31dd86c9162 to your computer and use it in GitHub Desktop.
Automate brew update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add
curl
to download it =>xx