Skip to content

Instantly share code, notes, and snippets.

@jordoh
Last active April 28, 2022 15:44
Show Gist options
  • Save jordoh/794054c43fcac557ee0e to your computer and use it in GitHub Desktop.
Save jordoh/794054c43fcac557ee0e to your computer and use it in GitHub Desktop.
bootstrapper
#!/bin/bash
# ---------------------------------------------------------------------------
# This script is intended to run in an environment that has nothing useful. It will install a minimal set of software
# to get ansible running, and let ansible take it from there
# ---------------------------------------------------------------------------
REPO_DIR="~/src/bonanza"
eval REPO_DIR=$REPO_DIR
BOOTSTRAP_DIR="~/src/bonanza/script/dev-env-bootstrapper"
eval BOOTSTRAP_DIR=$BOOTSTRAP_DIR
# ---------------------------------------------------------------------------
function print_heading {
echo "---------------------------------------------------------------------------"
echo $1
}
# ---------------------------------------------------------------------------
function install_homebrew {
print_heading "Installing homebrew"
which -s brew
if [[ $? != 0 ]] ; then
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
echo "Homebrew is already installed, skipping"
fi
}
# ---------------------------------------------------------------------------
function install_git {
print_heading "Installing git"
which -s git
if [[ $? != 0 ]] ; then
brew install git
else
echo "git is already installed, skipping"
fi
}
# ---------------------------------------------------------------------------
function install_ansible {
print_heading "Installing ansible"
which -s ansible
if [[ $? != 0 ]] ; then
brew install ansible
else
echo "ansible is already installed, skipping"
fi
}
# ---------------------------------------------------------------------------
function create_src_dir {
SRC_DIR="~/src"
eval SRC_DIR=$SRC_DIR
print_heading "Creating $SRC_DIR"
if [ ! -d "$SRC_DIR" ]; then
mkdir $SRC_DIR
else
echo "Directory exists, skipping"
fi
}
# ---------------------------------------------------------------------------
function clone_repository {
print_heading "Cloning repo into $REPO_DIR"
if [ ! -d "$REPO_DIR" ]; then
git clone git@github.com:bonanza-market/bonanza.git $REPO_DIR
else
echo "Directory exists, pulling instead"
cd $REPO_DIR
git pull
fi
}
# ---------------------------------------------------------------------------
function run_ansible {
print_heading "Running ansible"
cd $BOOTSTRAP_DIR
ansible-playbook -K -i inventory playbook.yml
}
# ---------------------------------------------------------------------------
function bootstrap_osx {
print_heading "Starting OS X bootstrap process"
install_homebrew
install_git
install_ansible
create_src_dir
clone_repository
run_ansible
}
# ---------------------------------------------------------------------------
function bootstrap_linux {
print_heading "Starting Linux bootstrap process"
print_heading "Adding ansible ppa"
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
# As of June 2017, Zesty doesn't have an ansible PPA build, so we'll use the yakkety build instead
# https://github.com/ansible/ansible/issues/24322
. /etc/lsb-release
if [[ "$DISTRIB_CODENAME" == "zesty" ]]; then
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu yakkety main" | sudo tee /etc/apt/sources.list.d/ansible-ubuntu-ansible-zesty.list > /dev/null
fi
sudo apt-get update
print_heading "Installing git + gpg + curl + ansible"
sudo apt-get install git gpg curl ansible
create_src_dir
clone_repository
run_ansible
}
# ---------------------------------------------------------------------------
if [[ "$OSTYPE" == "linux-gnu" ]]; then
bootstrap_linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
bootstrap_osx
else
echo "Unsupported OS '$OSTYPE', exiting"
fi
print_heading "Bootstrap process complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment