Skip to content

Instantly share code, notes, and snippets.

@davewalter
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davewalter/b945a275b0fb30512f69 to your computer and use it in GitHub Desktop.
Save davewalter/b945a275b0fb30512f69 to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
RUBY_VERSIONS=(2.1.2 2.1.6 2.2.2)
VAGRANT_VERSION=1.6.5
function print() {
local green='\033[0;32m'
local none='\033[0m'
echo -e "[${green}$1${none}] $2"
}
function prompt_to_continue() {
echo
read -p "Continue? (y/n): " continue
if [[ "$continue" != "y" ]]; then
echo "Aborting!"
exit 1
fi
echo
}
function install_smyck() {
print smyck "Installing color scheme..."
local smyck='{
"Ansi 0 Color" = { "Blue Component" = 0; "Green Component" = 0; "Red Component" = 0; };
"Ansi 1 Color" = { "Blue Component" = "0.1933501363"; "Green Component" = "0.2561769783"; "Red Component" = "0.7201576829"; };
"Ansi 10 Color" = { "Blue Component" = "0.2156862745"; "Green Component" = "0.9450980392"; "Red Component" = "0.768627451"; };
"Ansi 11 Color" = { "Blue Component" = "0.3019607961177826"; "Green Component" = "0.8823529481887817"; "Red Component" = "0.9960784316062927"; };
"Ansi 12 Color" = { "Blue Component" = "0.9411764740943909"; "Green Component" = "0.8117647171020508"; "Red Component" = "0.5529412031173706"; };
"Ansi 13 Color" = { "Blue Component" = 1; "Green Component" = "0.6039215686"; "Red Component" = "0.968627451"; };
"Ansi 14 Color" = { "Blue Component" = "0.8117647059"; "Green Component" = "0.8509803922"; "Red Component" = "0.4156862745"; };
"Ansi 15 Color" = { "Blue Component" = "0.9686274528503418"; "Green Component" = "0.9686274528503418"; "Red Component" = "0.9686274528503418"; };
"Ansi 2 Color" = { "Blue Component" = 0; "Green Component" = "0.663764596"; "Red Component" = "0.4915682375"; };
"Ansi 3 Color" = { "Blue Component" = 0; "Green Component" = "0.6470588235"; "Red Component" = "0.768627451"; };
"Ansi 4 Color" = { "Blue Component" = "0.768627451"; "Green Component" = "0.6392156863"; "Red Component" = "0.3843137255"; };
"Ansi 5 Color" = { "Blue Component" = "0.8"; "Green Component" = "0.5411764706"; "Red Component" = "0.7294117647"; };
"Ansi 6 Color" = { "Blue Component" = "0.5137255191802979"; "Green Component" = "0.4509803950786591"; "Red Component" = "0.125490203499794"; };
"Ansi 7 Color" = { "Blue Component" = "0.6297031044960022"; "Green Component" = "0.6298518180847168"; "Red Component" = "0.6297333240509033"; };
"Ansi 8 Color" = { "Blue Component" = "0.4799999892711639"; "Green Component" = "0.4799999892711639"; "Red Component" = "0.4799999892711639"; };
"Ansi 9 Color" = { "Blue Component" = "0.4862745098"; "Green Component" = "0.5137254902"; "Red Component" = "0.8392156863"; };
"Background Color" = { "Blue Component" = "0"; "Green Component" = "0"; "Red Component" = "0"; };
"Bold Color" = { "Blue Component" = 1; "Green Component" = 1; "Red Component" = 1; };
"Cursor Color" = { "Blue Component" = "0.7333333492279053"; "Green Component" = "0.7333333492279053"; "Red Component" = "0.7333333492279053"; };
"Cursor Text Color" = { "Blue Component" = 1; "Green Component" = 1; "Red Component" = 1; };
"Foreground Color" = { "Blue Component" = "0.9686274528503418"; "Green Component" = "0.9686274528503418"; "Red Component" = "0.9686274528503418"; };
"Selected Text Color" = { "Blue Component" = "0.9686274528503418"; "Green Component" = "0.9686274528503418"; "Red Component" = "0.9686274528503418"; };
"Selection Color" = { "Blue Component" = "0.5150196552276611"; "Green Component" = "0.4543989896774292"; "Red Component" = "0.1270008981227875"; };
}'
defaults write com.googlecode.iterm2 "Custom Color Presets" -dict-add Smyck "$smyck"
print smyck "Profile added"
# TODO: set profile as default
echo
}
function update_brew() {
print brew "Updating..."
pushd /usr/local/Library > /dev/null
git pull origin master
sudo chown -R pivotal:staff .
popd
brew update
if [[ -n "`brew list | grep brew-cask`" ]]; then
brew uninstall brew-cask
brew install brew-cask
fi
brew update
brew cask update
echo
}
function agree_to_xcode_license() {
print "xcode license" "Must be agreed to..."
sudo xcodebuild -license
echo
}
function install_xcode_cli_tools() {
set +e
xcode-select --install &>/dev/null
local status=$?
set -e
if [[ $status = 0 ]]; then
print "xcode cli tools" "Installing..."
prompt_to_continue
else
print "xcode cli tools" "Already installed, skipping..."
fi
echo
}
function install_dropbox() {
if [[ ! -e "$HOME/Applications/Dropbox.app" || ! -d "$HOME/Dropbox" ]]; then
print dropbox "Not found, installing..."
brew cask install dropbox --force
print dropbox "Waiting for $HOME/Dropbox directory to exist, follow installer steps..."
open $HOME/Applications/Dropbox.app
while [[ ! -d "$HOME/Dropbox" ]]; do
sleep 1
done
prompt_to_continue
else
print dropbox "Already installed, skipping..."
fi
print dropbox "Linking environment files..."
pushd $HOME > /dev/null
ln -sf $HOME/Dropbox/.bash_profile
ln -sf $HOME/Dropbox/pairs .pairs
ln -sf $HOME/Dropbox/vimrc .vimrc
ln -sf $HOME/Dropbox/Checkman
ln -sf $HOME/Dropbox/.flyrc
popd > /dev/null
echo
}
function install_git() {
if [[ -z "`which git`" ]]; then
print git "Not found, installing..."
brew install git
elif [[ -n "`brew outdated git`" ]]; then
print git "Updating..."
brew upgrade git
else
print git "Already installed, skipping..."
fi
echo
}
function install_mercurial() {
if [[ -z "`which hg`" ]]; then
print mercurial "Not found, installing..."
brew install mercurial
elif [[ -n "`brew outdated mercurial`" ]]; then
print mercurial "Updating..."
brew upgrade mercurial
else
print mercurial "Already installed, skipping..."
fi
echo
}
function install_direnv() {
if [[ -z "`which direnv`" ]]; then
print direnv "Not found, installing..."
brew install direnv
else
print direnv "Already installed, skipping..."
fi
echo
}
function install_golang() {
print golang "Setting up GOPATH..."
export GOPATH=$HOME/go
mkdir -p $GOPATH
pushd $GOPATH > /dev/null
ln -sf $HOME/workspace src
popd > /dev/null
if [[ -z "`which go`" ]]; then
print golang "Not found, installing..."
brew install go
else
print golang "Already installed, skipping..."
fi
echo
}
function install_vagrant() {
local cask="https://raw.githubusercontent.com/caskroom/homebrew-cask/76b126c9998904ea1f7cac5f9f1c5e7a1105431c/Casks/vagrant.rb"
if [[ -z "`which vagrant`" ]]; then
print vagrant "Not found, installing..."
brew cask install $cask --force
elif [[ "`vagrant -v | awk '{print $2}'`" != $VAGRANT_VERSION ]]; then
print vagrant "Changing version from `vagrant -v | awk '{print $2}'` to $VAGRANT_VERSION"
sudo rm -rf "`which vagrant`"
brew cask install $cask --force
else
print vagrant "Already installed, skipping..."
fi
echo
}
function install_boot2docker() {
if [[ -z "`which boot2docker`" ]]; then
print boot2docker "Not found, installing..."
brew cask install boot2docker
else
print boot2docker "Already installed, skipping..."
fi
if [[ -n "`boot2docker status 2>&1 | grep 'does not exist'`" ]]; then
print boot2docker "VM missing, initializing..."
boot2docker init
else
print boot2docker "VM already initialized"
fi
if [[ -z "`boot2docker status | grep 'running'`" ]]; then
print boot2docker "VM not running, booting..."
boot2docker up
else
print boot2docker "VM already running"
fi
echo
}
function install_ruby() {
if [[ -n "`brew list | xargs -n 1 | grep '^ruby$'`" ]]; then
print ruby "Uninstalling brew installed ruby..."
brew uninstall ruby
fi
if [[ "`brew outdated rbenv`" ]]; then
print ruby "Upgrading rbenv..."
brew upgrade rbenv
fi
if [[ "`brew outdated ruby-build`" ]]; then
print ruby "Upgrading ruby-build..."
brew upgrade ruby-build
fi
export RBENV_VERSION=system
for version in ${RUBY_VERSIONS[@]}; do
if [[ -z "`rbenv versions | awk '{print $1}' | grep $version`" ]]; then
print ruby "Missing version $version, installing..."
rbenv install $version
else
print ruby "Already installed $version, skipping..."
fi
done
echo
}
function install_ginkgo() {
print ginkgo "Installing latest..."
go get -u github.com/onsi/ginkgo/ginkgo
echo
}
function install_godep() {
print godep "Installing latest..."
go get -u github.com/tools/godep
echo
}
function install_spiff() {
print spiff "Installing latest..."
go get -u github.com/cloudfoundry-incubator/spiff
echo
}
function install_phantomjs() {
if [[ -z "`which phantomjs`" ]]; then
print phantomjs "Not found, installing..."
brew install phantomjs
else
print phantomjs "Already installed, skipping..."
fi
echo
}
function install_bosh() {
for version in ${RUBY_VERSIONS[@]}; do
export RBENV_VERSION=$version
if [[ -z "`gem list | grep bosh_cli`" ]]; then
print bosh "Missing on ruby $version, installing..."
gem install bosh_cli
else
print bosh "Already installed on ruby $version, skipping..."
fi
done
echo
}
function install_uaac() {
for version in ${RUBY_VERSIONS[@]}; do
export RBENV_VERSION=$version
if [[ -z "`gem list | grep cf-uaac`" ]]; then
print uaac "Missing on ruby $version, installing..."
gem install cf-uaac
else
print uaac "Already installed on ruby $version, skipping..."
fi
done
echo
}
function install_cf() {
if [[ -z "`which cf`" ]]; then
print cf "Not found, installing..."
pushd /usr/local/bin > /dev/null
curl -L "https://cli.run.pivotal.io/stable?release=macosx64-binary&source=github" -s | tar xz
chmod +x /usr/local/bin/cf
popd > /dev/null
else
print cf "Already installed, skipping..."
fi
echo
}
function install_pip() {
if [[ -z "`which pip`" ]]; then
print pip "Not found, installing..."
sudo easy_install pip
else
print pip "Already installed, skipping..."
fi
echo
}
function install_neovim() {
if [[ -z "`which nvim`" ]]; then
print neovim "Not found, installing..."
brew tap neovim/neovim
brew install --HEAD neovim
else
print neovim "Already installed, skipping..."
fi
print neovim "Setting up environment..."
pushd $HOME > /dev/null
mkdir -p .vim
ln -sf .vim .nvim
touch .vimrc
ln -sf .vimrc .nvimrc
popd > /dev/null
if [[ ! -d "$HOME/.nvim/bundle/Vundle.vim" ]]; then
print neovim "Installing vundle..."
mkdir -p $HOME/.nvim/bundle
git clone https://github.com/gmarik/Vundle.vim.git $HOME/.nvim/bundle/Vundle.vim
fi
print neovim "Installing plugins..."
sudo pip install neovim
nvim +PluginInstall +qall
echo
}
function install_slack() {
if [[ ! -e "$HOME/Applications/Slack.app" ]]; then
print slack "Not found, installing..."
brew cask install slack
else
print slack "Already installed, skipping..."
fi
echo
}
function install_sequel_pro() {
if [[ ! -e "$HOME/Applications/Sequel Pro.app" ]]; then
print "sequel pro" "Not found, installing..."
brew cask install sequel-pro
else
print "sequel pro" "Already installed, skipping..."
fi
echo
}
function install_aws_cli() {
if [[ -z "`which aws`" ]]; then
print aws-cli "Not found, installing..."
brew install awscli
else
print aws-cli "Already installed, skipping..."
fi
echo
}
function configure_mysql_server() {
local mysql_plist=$HOME/Library/LaunchAgents/homebrew.mxcl.mysql.plist
print mysql "Stopping the server..."
launchctl unload $mysql_plist
print mysql "Configuring..."
cat <<-EOF > /tmp/mysql-init
RENAME USER 'root'@'localhost' TO 'root'@'%';
SET PASSWORD FOR 'root'@'%' = PASSWORD('root');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
EOF
sed -i bak 's/127.0.0.1/0.0.0.0/g' $mysql_plist
while [[ -n "`ps aux | grep mysql | grep -v grep | grep -v bin/sh | awk '{print \$2}'`" ]]; do
print mysql "Waiting for mysql to unload..."
sleep 1
done
sudo -u pivotal mysqld_safe --user=pivotal --init-file=/tmp/mysql-init &
set +e
while [[ -z "`ps aux | grep mysql | grep -v grep | grep -v bin/sh | grep -v sudo | awk '{print \$2}'`" ]]; do
print mysql "Waiting for mysql to configure..."
sleep 1
done
local mysql_pid=`ps aux | grep mysql | grep -v grep | grep -v bin/sh | grep -v sudo | awk '{print \$2}'`
sleep 1
kill $mysql_pid
while [[ -n "`ps aux | grep mysql | grep -v grep | grep -v bin/sh | grep -v sudo | awk '{print \$2}'`" ]]; do
print mysql "Waiting for mysql to finish..."
sleep 1
done
set -e
print mysql "Starting the server..."
launchctl load $mysql_plist
echo
}
function launch_keychain_menu_item() {
if [[ -z "`defaults read com.apple.systemuiserver | grep '/Applications/Utilities/Keychain Access.app/Contents/Resources/Keychain.menu'`" ]]; then
print keychain "Menu item missing, starting..."
open "/Applications/Utilities/Keychain Access.app/Contents/Resources/Keychain.menu"
else
print keychain "Menu item exists, skipping..."
fi
echo
}
function set_hostname() {
print hostname "Setting..."
read -p "Your hostname is set to \"`hostname`\". Do you want to change it? (y/n): " change
if [[ "$change" = "y" ]]; then
read -p "What is your new hostname?: " myhostname
sudo scutil --set HostName $myhostname
sudo scutil --set LocalHostName $myhostname
sudo scutil --set ComputerName $myhostname
export HOSTNAME=`hostname`
dscacheutil -flushcache
print hostname "Set to \"$myhostname\""
else
print hostname "OK"
fi
echo
}
function install_checkman() {
print checkman "Installing..."
curl -s https://raw.githubusercontent.com/cppforlife/checkman/master/bin/install | bash -s > /dev/null 2>&1
defaults write com.tomato.Checkman stickies.disabled -bool YES
echo
}
function load_profile() {
print profile "Loading..."
set +ue
source $HOME/.bash_profile
set -ue
echo
}
function finish() {
local green='\033[0;32m'
local none='\033[0m'
echo
echo -e "${green}FINISHED${none}"
echo "Note: some of these changes require a logout/restart to take effect."
read -p "Would you like to reboot? (y/n): " shouldReboot
echo "Goodbye"
if [[ "$shouldReboot" = "y" ]]; then
echo "Rebooting..."
sudo reboot
fi
echo
}
function configure_osx() {
print osx "Configuring Dock..."
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock autohide-delay -float 0
defaults write com.apple.dock orientation bottom
killall Dock
print osx "Configuring Finder..."
defaults write com.apple.finder AppleShowAllFiles -bool true
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
defaults write com.apple.finder NewWindowTarget -string "PfLo"
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/workspace/"
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
sudo defaults write /Library/Preferences/.GlobalPreferences.plist _HIEnableThemeSwitchHotKey -bool true
chflags nohidden ~/Library
killall Finder
print osx "Configuring Screensaver.."
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
}
function install_chromedriver() {
if [[ -z "`which chromedriver`" ]]; then
print chromedriver "Not found, installing..."
brew install chromedriver
else
print chromedriver "Already installed, skipping..."
fi
echo
}
function install_node() {
if [[ -z "`which node`" ]]; then
print node "Not found, installing..."
brew install node
else
print node "Already installed, skipping..."
fi
echo
}
function brew_upgrade() {
if [[ -n "`brew outdated`" ]]; then
read -p "Brew has found outdated packages. Would you like to upgrade them? (y/n): " upgrade
echo
if [[ "$upgrade" = "y" ]]; then
for pkg in `brew outdated`; do
if [[ -n "`brew outdated $pkg`" ]]; then
read -p "$pkg is outdated. Would you like to upgrade? (y/n): " upgradePkg
if [[ "$upgradePkg" = "y" ]]; then
brew upgrade $pkg
echo
fi
fi
done
fi
fi
echo
}
set_hostname
configure_osx
install_xcode_cli_tools
agree_to_xcode_license
update_brew
install_smyck
install_dropbox
install_git
install_mercurial
install_pip
install_direnv
install_aws_cli
install_checkman
install_golang
install_cf
install_ginkgo
install_godep
install_spiff
install_node
install_ruby
install_bosh
install_uaac
install_vagrant
install_boot2docker
install_phantomjs
install_chromedriver
install_neovim
install_slack
install_sequel_pro
configure_mysql_server
launch_keychain_menu_item
load_profile
brew_upgrade
finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment