Skip to content

Instantly share code, notes, and snippets.

@mahmoudimus
Last active March 31, 2019 18:43
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 mahmoudimus/5dba91987f1c55d3ae90eebc009fcf9b to your computer and use it in GitHub Desktop.
Save mahmoudimus/5dba91987f1c55d3ae90eebc009fcf9b to your computer and use it in GitHub Desktop.
fix up mac reinstall

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment