Skip to content

Commit

Permalink
feat(bootstrap): check for executables before install
Browse files Browse the repository at this point in the history
This will (hopefully) make the build pass, but it will prove problematic
in a real scenario. I can upgrade openssl and python on Travis before
running the script, but I won't be on a fresh MacBook. In that case I'll
likely hit the same certificate error when running ansible-galaxy
install. Maybe the one-line bootstrap dream is over...
  • Loading branch information
eliasnorrby committed Sep 30, 2020
1 parent 699d878 commit af9f0ef
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,45 @@ _get_repo_snapshot() {
curl -sL $TARBALL_URL | tar xz
}

# check if a command is available
function _is_callable() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null || return 1
done
}

_msg "Downloading repository snapshot from eliasnorrby/dotfiles@$DOTFILES_VERSION..."
cd $(mktemp -d)
_get_repo_snapshot
cd eliasnorrby-dotfiles*

_msg "Installing python 3..."
curl "https://www.python.org/ftp/python/3.7.9/python-3.7.9-macosx10.9.pkg" -o "python3.pkg"
sudo installer -pkg python3.pkg -target /
export PATH=/Library/Frameworks/Python.framework/Versions/3.7/bin:$PATH

_msg "Installing pip..."
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
if ! _is_callable python3; then
_msg "Installing python 3..."
curl "https://www.python.org/ftp/python/3.7.9/python-3.7.9-macosx10.9.pkg" -o "python3.pkg"
sudo installer -pkg python3.pkg -target /
export PATH=/Library/Frameworks/Python.framework/Versions/3.7/bin:$PATH
else
_msg "python 3 already installed"
fi

_msg "Installing ansible..."
sudo -H pip3 install ansible
if ! _is_callable pip3; then
_msg "Installing pip..."
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
else
_msg "pip already installed"
fi

_msg "Installing playbook requirements..."
cd _provision
ansible-galaxy install -r requirements.yml

if ! _is_callable ansible; then
_msg "Installing ansible..."
sudo -H pip3 install ansible

_msg "Installing playbook requirements..."
ansible-galaxy install -r requirements.yml
else
_msg "ansible already installed"
fi

_msg "Running the playbook..."
ansible-playbook playbook.yml --tags "$ANSIBLE_TAGS" "$ANSIBLE_FLAGS"
Expand Down

0 comments on commit af9f0ef

Please sign in to comment.