I purchased a new Macbook and I restored my files from another mac via migration assistant.
As I was using Brew, I saw a lot of errors such as:
Upgrading railwaycat/emacsmacport/emacs-mac --with-natural-title-bar
Error: An exception occurred within a child process:
RuntimeError: /usr/local/opt/libevent not present or broken
Please reinstall libevent. Sorry :(
After a while, it seemed that there were several issues that could be remediated by a simple script. I am putting this here in case someone else runs across it:
function fixit { brew unlink $1 && brew link --overwrite --force $1; }
while true; do
OUTPUT="$(brew upgrade 2>&1)"
RESULT=$?
(>&2 echo "$OUTPUT")
if [ "$RESULT" -eq 0 ]; then break; fi
MISSING=$(echo "$OUTPUT" | tail -1)
(>&2 echo "$MISSING")
LIB=$(echo "$MISSING" | cut -d ' ' -f 3 | tr -d '.')
(>&2 echo "$LIB")
fixit "$LIB"
RESULT=$?
if [ "$RESULT" -ne 0 ]; then
brew reinstall "$LIB";
brew reinstall "$LIB"; # for some reaosn, I had to do this twice
fi
RESULT=1
done