#!/usr/bin/env bash set -eu set -o pipefail : ${NAPSAC_PATH:="$HOME/napsac"} : ${NAPSAC_BRANCH:="master"} ARGS=('') for a in "$@"; do ARGS=(${ARGS[@]} "$a") done clone_napsac() { local git_dir="$NAPSAC_PATH/.git" if [ -d "$git_dir" ]; then echo 'Updating repo...' if [ "$(git --git-dir="$git_dir" symbolic-ref --short HEAD 2> /dev/null)" != "master" ]; then echo 'skip (working on a non-master branch)' return fi if ! git --git-dir="$git_dir" diff --no-ext-diff --quiet --exit-code > /dev/null 2>&1; then echo 'skip (unstaged changes present)' return fi if ! git --git-dir="$git_dir" diff-index --cached --quiet HEAD -- > /dev/null 2>&1; then echo 'skip (uncommitted changes present)' return fi git --git-dir="$git_dir" pull origin master echo 'done' elif ! [ -d "$NAPSAC_PATH" ]; then echo 'Cloning repo...' git clone git://github.com/ngtk/napsac.git --branch $NAPSAC_BRANCH $NAPSAC_PATH echo 'done' fi } check_xcode_license_approved() { echo 'Agreeing to Xcode license...' local has_error=0 if ! [[ "$(/usr/bin/xcrun clang 2>&1 || true)" =~ 'license' ]]; then echo 'skip (already approved)' return fi sudo expect -c ' set timeout 3 spawn xcodebuild -license expect { timeout { exit 2 } -exact "for more" { send "G" exp_continue } -exact "agree, print, cancel" { send "agree\n" exp_continue } -exact "You can view the license agreements" { exit 0 } } ' > /dev/null || has_error=1 [ $has_error -eq 1 ] && sudo xcodebuild -license echo 'done' } install_homebrew() { command -v 'brew' > /dev/null 2>&1 && return echo 'Installing homebrew...' ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null echo 'done' } install_ansible() { command -v 'ansible' > /dev/null 2>&1 && return echo 'Installing ansible...' brew install ansible echo 'done' } run_provisioning() { $NAPSAC_PATH/provisioning/play.sh ${ARGS[@]} } main() { check_xcode_license_approved clone_napsac install_homebrew install_ansible run_provisioning } main