Created
August 20, 2015 13:23
-
-
Save smt/55f8f7fccc014454dbe5 to your computer and use it in GitHub Desktop.
PTHIELE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SRC_DIRECTORY="$HOME/Developer" | |
SSH_DIRECTORY="$HOME/.ssh" | |
ANSIBLE_DIRECTORY="$SRC_DIRECTORY/ansible" | |
ANSIBLE_CONFIGURATION_DIRECTORY="$HOME/.anthrobasebox" | |
function pause(){ | |
read -p "$*" | |
} | |
function gen_scm_key() { | |
echo "Info | Configure | $1 SSH key" | |
mkdir -p $SSH_DIRECTORY | |
ssh-keygen -f $SSH_DIRECTORY/$2 -t rsa -N '' | |
cat $SSH_DIRECTORY/$2.pub | pbcopy | |
echo "About to open $1 in the browser. Log in, navigate to your account settings, and paste the public key (now copied to your clipboard) as a new SSH key. Name it something meaningful, like 'URBN laptop'." | |
sleep 6 | |
open https://$1 | |
sleep 3 | |
pause "Press [Enter] key to continue..." | |
echo "Creating a SSH config entry using '$2' (you may want to edit this later)." | |
cat <<EOF >> $SSH_DIRECTORY/config | |
Host $1 | |
Hostname $1 | |
User git | |
IdentityFile %d/.ssh/$2 | |
EOF | |
} | |
if [[ -x /usr/bin/sw_vers ]]; then | |
OSX_VERSION=$(sw_vers | grep 'ProductVersion:' | awk '{print $2}' | cut -d . -f 1,2 -) | |
else | |
echo "Error | OS Check | osx" | |
return 1 | |
fi | |
# Download and install Command Line Tools | |
xcode-select -p > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Info | Install | xcode" | |
xcode-select --install > /dev/null 2>&1 | |
pause "Press [Enter] key to continue..." | |
fi | |
# Download and install Homebrew | |
if [[ ! -x /usr/local/bin/brew ]]; then | |
echo "Info | Install | homebrew" | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
echo "Info | Install | caskroom" | |
brew install caskroom/cask/brew-cask | |
fi | |
# Modify the PATH | |
export PATH=/usr/local/bin:$PATH | |
# Download and install git | |
if [[ ! -x /usr/local/bin/git ]]; then | |
echo "Info | Install | git" | |
brew install git | |
fi | |
# Download and install python | |
if [[ ! -x /usr/local/bin/python ]]; then | |
echo "Info | Install | python" | |
brew install python --framework --with-brewed-openssl | |
fi | |
# Download and install vim | |
if [[ ! -x /usr/local/bin/vim ]]; then | |
echo "Info | Install | vim" | |
brew install vim --override-system-vi --with-lua --with-tcl | |
fi | |
# Download and install cowsay | |
if [[ ! -x /usr/local/bin/cowsay ]]; then | |
echo "Info | Install | cowsay" | |
brew install cowsay | |
fi | |
# Download and install Ansible | |
if [[ ! -x /usr/local/bin/ansible ]]; then | |
echo "Info | Install | ansible" | |
brew install ansible | |
fi | |
# Ensure we have the required libs | |
pip install -Iv --disable-pip-version-check pip==6.1.1 | |
pip install -Iv --disable-pip-version-check pyyaml jinja2 | |
# Make the code directory | |
mkdir -p $SRC_DIRECTORY | |
# Add a BitBucket SSH key? | |
grep -ri "Host bitbucket.org" $SSH_DIRECTORY > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
while true; do | |
read -p "Would you like to add a SSH key to your BitBucket account for this machine? [y/N]" yn | |
case $yn in | |
[Yy]* ) gen_scm_key "bitbucket.org" "id_bitbucket" | |
break;; | |
* ) break;; | |
esac | |
done | |
fi | |
# Add a GitHub SSH key? | |
grep -ri "Host github.com" $SSH_DIRECTORY > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
while true; do | |
read -p "Would you like to add a SSH key to your GitHub account for this machine? [y/N]" yn | |
case $yn in | |
[Yy]* ) gen_scm_key "github.com" "id_github" | |
break;; | |
* ) break;; | |
esac | |
done | |
fi | |
# Don't use the git protocol | |
cat <<EOF >> $HOME/.gitconfig | |
[url "https://"] | |
insteadOf = "git://" | |
EOF | |
# Clone down ansible | |
if [[ ! -d $ANSIBLE_DIRECTORY ]]; then | |
git clone -b devel https://github.com/ansible/ansible.git $ANSIBLE_DIRECTORY | |
cd $ANSIBLE_DIRECTORY && \ | |
git reset --hard 982bad78862029346577e805be9f33a73ef2ec84 && \ | |
git submodule update --recursive --init | |
fi | |
# Use the forked Ansible | |
source $ANSIBLE_DIRECTORY/hacking/env-setup > /dev/null | |
# Clone down the Ansible repo | |
if [[ ! -d $ANSIBLE_CONFIGURATION_DIRECTORY ]]; then | |
echo "Info | Configure | ansible.d" | |
git clone [email protected]:anthroweb/anthrobasebox.git $ANSIBLE_CONFIGURATION_DIRECTORY | |
(cd $ANSIBLE_CONFIGURATION_DIRECTORY && git submodule update --init) | |
fi | |
# Provision the box | |
echo "Info | Configure | ansible-playbook" | |
$ANSIBLE_DIRECTORY/bin/ansible-playbook -e "username=$(whoami)" -K -i $ANSIBLE_CONFIGURATION_DIRECTORY/inventories/osx $ANSIBLE_CONFIGURATION_DIRECTORY/site.yml --connection=local | |
# Link the casks. | |
echo "Info | Configure | link-casks" | |
$ANSIBLE_CONFIGURATION_DIRECTORY/link-casks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment