Skip to content

Instantly share code, notes, and snippets.

@kaylarose
Last active August 29, 2015 14:09
Show Gist options
  • Save kaylarose/ceae2baa4b6898d6ea00 to your computer and use it in GitHub Desktop.
Save kaylarose/ceae2baa4b6898d6ea00 to your computer and use it in GitHub Desktop.
Cobblestone: Bootstrap a Mac for Hacking & Development
#!/bin/bash
# Cobblestone: Bootstrap a Mac for Hacking & Development
# Cobble together a decent Mac Developer setup from scratch
# Author: Kayla Hinz
# LICENSE: MIT
#
# TODO:
# ANSI-Fun!
function print_section_header {
echo ""
echo "#######################"
echo "${1}"
echo "#######################"
}
function print_section_subheader {
echo "-----------------------"
echo "${1}"
echo "-----------------------"
}
function confirm_prompt {
#source http://stackoverflow.com/questions/3231804/in-bash-how-to-add-are-you-sure-y-n-to-any-command-or-alias
# call with a prompt string or use a default
local text="${1}"
read -r -p "${text:-Are you sure?} [y/N] " answer
if [[ $answer == "y" || $answer == "Y" ]]; then
true
else
false
fi
}
function prompt_for_directory_and_return_valid {
local text="${1}"
read -r -p "${text:-Please enter a directory} : " directory
if [ -d "$directory" ]; then
$directory
else
echo "WARNING: The directory is invalid. Please ensure it exists.\n\tDirectory: $directory\n"
false
fi
}
function cask_install_apps {
echo ""
local app_list=$1[@]
local description="${2}"
local prompt="Install ${description} Apps?"
local apps=("${!app_list}")
if confirm_prompt "$prompt"; then
echo "Preparing to install:"
printf -- '\t%s\n' "${apps[@]}"
echo "to /Users/YOU/Applications ..."
brew cask install --appdir="/Applications" ${apps[@]}
fi
}
function brew_install_formulas {
echo ""
local formula_list=$1[@]
local description="${2}"
local prompt="Install ${description} Formulas?"
local formulas=("${!formula_list}")
if confirm_prompt "$prompt"; then
echo "Preparing to Brew:"
printf -- '\t%s\n' "${formulas[@]}"
brew install ${formulas[@]}
fi
}
function configure_mackup {
echo ""
local cfg_file=~/.mackup.cfg
local cfg_header="# -- Mackup Configuration File --
# Mackup Info:
# https://github.com/lra/mackup
# Config Documentation:
# https://github.com/lra/mackup/blob/master/doc/.mackup.cfg
#
"
local cfg_followup="Your Mackup configuration is located at: ${cfg_file}
see: https://github.com/lra/mackup/blob/master/doc/.mackup.cfg for more info."
local cfg_google_drive="[storage]\nengine = google_drive\n"
local cfg_disk="[storage]\nengine = file_system\n"
# Don't explictly write a value since this is the default.
local cfg_dropbox="# Defaults to dropbox if none defined\n# [storage]\n# engine = dropbox\n"
if [ -f $cfg_file ]; then
echo "ERROR: A Mackup file already exists at:${cfg_file}. Please edit it manually."
else
echo "Where would you like to store your Mackup Backups?..."
echo "NOTE: If you want to use Dropbox or Google Drive,
make sure they are setup on your local drive, and linked to your
account BEFORE entering an option below. If they are setup, Mackup
will automatically find the correct folder for backup."
storage_options=("Dropbox (default)" "Google Drive" "Disk" "Setup Mackup later.")
# Storgae Engine in Config file Defaults to dropbox if none chosen.
# Options: dropbox|google_drive|file_system
# see: https://github.com/lra/mackup/blob/master/doc/.mackup.cfg for more info.
select opt in "${storage_options[@]}"
do
case $opt in
"Dropbox (default)")
echo "Configuring Mackup for Dropbox..."
echo -e "$cfg_header" >> $cfg_file
echo -e "$cfg_dropbox" >> $cfg_file
echo "$cfg_followup"
break
;;
"Google Drive")
echo "Configuring Mackup for Google Drive..."
echo -e "$cfg_header" >> $cfg_file
echo -e "$cfg_google_drive" >> $cfg_file
echo "$cfg_followup"
break
;;
"Disk")
mackup_hint="Enter an existing local directory to store your Mackup backup in:"
user_storagepath=prompt_for_directory_and_return_valid "$mackup_hint"
echo "$user_storagepath"
if [ $user_storagepath != false ]; then
echo -e "$cfg_header" >> $cfg_file
echo -e "$cfg_disk" >> $cfg_file
echo -e "path = ${user_storagepath}\n" >> $cfg_file
echo "$cfg_followup"
fi
break
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
fi
}
###############################################################################
# Pre-Reqs
###############################################################################
# 1) Bootstrap all the tools we will need to do the rest of our setup.
print_section_header "### Pre-Reqs and Bootstrapping ###"
print_section_subheader "### Pre-Requisites ###"
# Install XCode CLI Tools
echo "Validating Requirement: XCode Command Line tools..."
if test ! $(which xcode-select); then
echo "Installing XCode Command Line tools..."
xcode-select --install
fi
print_section_subheader "### OS Package, App, and Profile Management ###"
echo "Validating Requirement: Homebrew..."
#### Boostrap Homebrew ####
# Check for Homebrew, Install if we don't have it
if test ! $(which brew); then
echo "Installing homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Fix it up & Update homebrew recipes
brew doctor
brew update
hint="Cask for Application Management (http://caskroom.io)"
formulas=(
"caskroom/cask/brew-cask"
)
brew_install_formulas formulas "$hint"
hint="Reference .bashrc in .bash_profile?"
if confirm_prompt "$hint"; then
reference="if [ -f ~/.bashrc ]; then \nsource ~/.bashrc\nfi"
echo -e "$reference" >> ~/.bash_profile
fi
###############################################################################
# Foundation
###############################################################################
# 2) All right, let's start bootstrapping a minimal tech foundation.
# Sources:
# http://lapwinglabs.com/blog/hacker-guide-to-setting-up-your-mac
print_section_header "### Basic Tools & Utils ###"
#### Core Updates ####
hint="Updates to core unix tools? (don't do this unless you will remember to run brew upgrade when vulnerabilities spring up)"
# Install:
# - GNU core utilities (those that come with OS X are outdated)
# - Bash 4
# - GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
formulas=(
coreutils
findutils
bash
)
brew_install_formulas formulas "$hint"
#### Add-On Utils ####
hint="Basic Helper Utils (ack, wget, imagemagick, etc)"
formulas=(
wget
ack
imagemagick
)
brew_install_formulas formulas "$hint"
hint="Source Control Tools (git, hg, svn)"
formulas=(
git
svn
hg
)
brew_install_formulas formulas "$hint"
hint="Developer OS Exensions (Quicklook, Colorpickers)"
apps=(
colorpicker-developer
colorpicker-hex
jsonlook
quicklook-csv
)
cask_install_apps apps "$hint"
hint="Text Editors (VimR, Textmate, etc.)"
apps=(
atom
macvim
vimr
textmate
)
cask_install_apps apps "$hint"
hint="Networking (Charles Proxy, etc.)"
apps=(
charles
)
cask_install_apps apps "$hint"
###############################################################################
# Fun
###############################################################################
print_section_header "### Developer Environments ###"
print_section_subheader "### Containers ###"
hint="Virtual Environments (Vagrant, Virtual Box, etc.)"
apps=(
vagrant
virtualbox
kitematic
)
cask_install_apps apps "$hint"
hint="Docker & Fig"
formulas=(
docker
fig
)
brew_install_formulas formulas "$hint"
#### Rubyists ####
print_section_subheader "### Ruby Foundation ###"
hint="Latest stable Ruby"
formulas=(
ruby
)
brew_install_formulas formulas "$hint"
hint="RVM: Ruby Version Manager (http://rvm.io)"
if confirm_prompt "$hint"; then
echo "Installing RVM and allowing it to use brew for lib management"
curl -sSL https://get.rvm.io | bash -s stable --autolibs=homebrew
echo "Appending RVM info to .bashrc"
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> .bashrc
echo "Setting up tab-completion for RVM"
echo '[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion'
echo "Loading RVM in current session"
source ~/.rvm/scripts/rvm
echo "Installing the Latest Stable version of Ruby"
command rvm install ruby --latest
echo "Others available:"
command rvm list known
fi
#### Pythonistas ####
print_section_subheader "### Python Foundation ###"
hint="Python (2.7 & 3)"
formulas=(
python
python3
)
brew_install_formulas formulas "$hint"
hint="Pycharm"
apps=(
pycharm
)
cask_install_apps apps "$hint"
command sudo pip install virtualenv
#### Node ####
print_section_subheader "### NodeJS Foundation ###"
hint="Node & npm"
formulas=(
npm
node
bower
)
brew_install_formulas formulas "$hint"
#### Databases ####
print_section_subheader "### Database Tools ###"
hint="Database GUI"
apps=(
induction
)
cask_install_apps apps "$hint"
hint="Databases (Mongo, Postgres, etc.)"
formulas=(
postgresql
redis
mongodb
)
brew_install_formulas formulas "$hint"
# TODO Run this after mongo install
# mkdir -p /data/db
hint="Do you want to install Genghis app for Mongo management?"
if confirm_prompt "$hint"; then
gem install genghisapp
fi
#### Google/GAE ####
print_section_subheader "### Google App Engine/Cloud SDK ###"
hint="Google Developer SDK Tools &"
apps=(
google-cloud-sdk
googleappenginelauncher
)
cask_install_apps apps "$hint"
#### iOS/Cocoa/NSHipsters ####
print_section_subheader "### iOS/Cocoa ###"
hint="iOS & Cocoa Tools &"
apps=(
appcode
cert-quicklook
crashlytics
# hockeyapp
# testflight
ifunbox
reflector
)
cask_install_apps apps "$hint"
#### Android ####
print_section_subheader "### Android Foundation ###"
hint="Java via Cask"
apps=(
java
)
cask_install_apps apps "$hint"
hint="Ant & Tomcat"
formulas=(
ant
tomcat
)
brew_install_formulas formulas "$hint"
hint="Android Developer Tools &"
apps=(
crashlytics
# hockeyapp
virtualbox
genymotion
# jenv
# android-studio
# android-studio-bundle
)
cask_install_apps apps "$hint"
###############################################################################
# Misc. (Edit this with your favorite apps & tools)
# Casks: https://github.com/caskroom/homebrew-cask/tree/master/Casks
###############################################################################
#### Misc Bloatware ####
print_section_subheader "### Misc Tools and Apps ###"
hint="Alternative Browsers (Chrome, etc.)"
apps=(
google-chrome
firefox
)
cask_install_apps apps "$hint"
hint="Social Apps (Skype, etc.)"
apps=(
skype
adium
google-hangouts
)
cask_install_apps apps "$hint"
hint="Video/Streaming/AirPlay"
apps=(
beamer
vlc
)
cask_install_apps apps "$hint"
hint="Other (fork or edit this script to add your favorites)"
apps=(
daisydisk
dash
cyberduck
evernote
iexplorer
kaleidoscope
dropbox
google-drive
sourcetree
)
cask_install_apps apps "$hint"
# Final cleanup of leftover artifacts
brew cleanup
###############################################################################
# Backup
###############################################################################
# 3) Now that everything is installed, back up my mac.
print_section_header "### Back it up! ###"
print_section_subheader "### Backup your shiny new Settings? ###"
hint="Do you want to use Mackup to Backup your App Preferences and Configuration Files?"
if confirm_prompt "$hint"; then
echo "Installing Mackup..."
brew install mackup
echo "Configuring Mackup..."
configure_mackup
echo "Running Mackup for intial backup"
mackup backup
fi
###############################################################################
# OS Swizzling
###############################################################################
# 4) Setup your OS to do what you want
# EPIC Source: https://gist.github.com/brandonb927/3195465
print_section_header "### OS Customizations ###"
print_section_subheader "### Swizzle you Mac OS settings ###"
hint="Do you want to customize your Core OS further? (see https://gist.github.com/brandonb927/3195465)"
if confirm_prompt "$hint"; then
echo "Starting OSX customization script. Proceed at own risk!!!!!"
echo "**** Will most likely kill your Terminal Session on completion ****"
sh -ci "$(curl -fsSL https://gist.github.com/brandonb927/3195465/raw)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment