diff --git a/baremetal-bootstrap b/baremetal-bootstrap new file mode 100644 index 0000000..417e95b --- /dev/null +++ b/baremetal-bootstrap @@ -0,0 +1,110 @@ +#!/usr/bin/env bash + +#--------------------------------------------------------------------- +usage () +{ + cat < + + Should be run as the user the app will run as on the target server. + +EOT + + exit ${1:-0} # Exit with code 0 unless an arg is passed to the method. +} +if [ "$1" = '-h' ]; then + usage +fi + + +# Set up working vars. +REPO_CLONE_URL=${1} +GIT_BRANCH=${2} +APP_ENV=${3} +INSTALL_DIR="/var/www" +BOOTSTRAP_SCRIPT="./bootstrap.sh" + + +# Validate input and environment. +if [ -z "$REPO_CLONE_URL" ] ; then + echo "!! Must provide git repo URL as first arg (https recommended over git/ssh)." + exit 1 +fi + +if [ -z "$GIT_BRANCH" ] ; then + echo "!! Must provide desired git branch as second arg." + exit 2 +fi + +if [ -z "$APP_ENV" ] ; then + echo "!! Must provide desired APP_ENV as third arg." + exit 3 +fi + +if [ -d "${INSTALL_DIR}" ] && [ -n $(find "${INSTALL_DIR}" -maxdepth 0 -type d -empty 2>/dev/null) ]; then + echo "!! Installation directory is not empty. Aborting." + exit 4 +fi + + +# main() + +if [ -z "$(which git)" ]; then + echo "## Installing git." + sudo apt-get -y update + sudo apt-get -y install git-core build-essential +elif git --version 2>&1 >/dev/null | grep -q 'xcode-select'; then + echo "## Triggering Xcode Command Line Tools installation. Either complete" + echo "## that process or install git into your PATH yourself, then press" + echo "## [ENTER] to continue." + read WAIT_FOR_INSTALL_TO_FINISH + if [ ! -x /Library/Developer/CommandLineTools/usr/bin/git ]; then + echo "!! Git installation appears to have failed." + echo "!! Please manually install and retry. Aborting." + exit 5 + fi +else + echo "## Git appears to already be installed." +fi + +# Alternative fully automated approach: +# Ref: https://apple.stackexchange.com/a/121044/17403 +# +# xcode-select --install +# sleep 1 +# osascript <