#!/bin/bash set -e # i'm not crazy about this because there exists at least one ansible module # to install and manage homebrew. but there's a chicken and egg problem because # python and ansible need to be installed somehow and the best way to do that # on macos is with homebrew... if [[ -z $MF_HOMEBREW_STYLE ]]; then echo >&2 "error: please supply the brewfile to install" exit 1 fi if command -v brew > /dev/null 2>&1; then echo >&2 "error: homebrew is already installed!" echo >&2 "error: please run brew bundle install directly" exit 1 fi # disable homebrew analytics export HOMEBREW_NO_ANALYTICS=1 # prompt for sudo password right away sudo echo -n if [[ $(uname -m) == arm64 ]]; then # install rosetta _before_ homebrew because some installers need it sudo /usr/sbin/softwareupdate --install-rosetta --agree-to-license fi # i'm really not a fan of this pattern but I don't have a better idea right now hburl=https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh /bin/bash -c "$(curl -fsSL "$hburl")" if [[ $(uname -m) == arm64 ]]; then eval "$(/opt/homebrew/bin/brew shellenv)" else eval "$(/usr/local/bin/brew shellenv)" fi if ! command -v brew > /dev/null 2>&1; then echo >&2 "error: it appears that homebrew installation was not successful" exit 1 fi wdir="$(mktemp -d)" sdir="$(pwd)" cd "$wdir" git clone https://github.com/mfinelli/arch-install.git cd arch-install/macos if [[ ! -f $MF_HOMEBREW_STYLE.brewfile ]]; then cd "$sdir" rm -rf "$wdir" echo >&2 "error: unable to find brewfile $MF_HOMEBREW_STYLE" exit 1 fi brew bundle install --file "$MF_HOMEBREW_STYLE.brewfile" if ! command -v ansible-playbook > /dev/null 2>&1; then cd "$sdir" rm -rf "$wdir" echo >&2 "error: ansible was not installed so we can't proceed" exit 1 fi # for stuff that we can't manage with homebrew ansible-galaxy install -r requirements.yml ansible-playbook "$MF_HOMEBREW_STYLE.yml" cd "$sdir" rm -rf "$wdir" exit 0