Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 394 lines (327 sloc) 12.5 KB
#!/usr/bin/env bash
# Welcome to the thoughtbot laptop script!
# Be prepared to turn your laptop (or desktop, no haters here)
# into an awesome development machine.
# _ __ _
# | |__ _ __ _____ __ / _| ___ _ __ _ __ ___ _ _| | __ _ ___
# | '_ \| '__/ _ \ \ /\ / / | |_ / _ \| '__| '_ ` _ \| | | | |/ _` |/ _ \
# | |_) | | | __/\ V V / | _| (_) | | | | | | | | |_| | | (_| | __/
# |_.__/|_| \___| \_/\_/ |_| \___/|_| |_| |_| |_|\__,_|_|\__,_|\___|
# These are the apps installed by Homebrew
brew_formulae=(autoenv colordiff ctags tmux vim gh docker graphviz wget curl
elasticsearch postgresql redis mongodb memcached mysql
reattach-to-user-namespace imagemagick qt watch
erlang elixir go
nvm
pyenv pyenv-virtualenv pyenv-virtualenvwrapper
rbenv rbenv-binstubs rbenv-bundler ruby-build
zsh zsh-completions zsh-syntax-highlighting)
# _ _
# | |__ _ __ _____ __ ___ __ _ ___| | _____
# | '_ \| '__/ _ \ \ /\ / / / __/ _` / __| |/ / __|
# | |_) | | | __/\ V V / | (_| (_| \__ \ <\__ \
# |_.__/|_| \___| \_/\_/ \___\__,_|___/_|\_\___/
# These are mac apps that brew cask can manage
brew_casks=(alfred anki anvil atom dash emacs flux firefox github-desktop
google-chrome iterm2 java spotify launchrocket skype vox vlc typora
transmission keycastr kindle xquartz
vagrant vagrant-manager virtualbox virtualbox-extension-pack)
# _ _ _ _
# | \ | | ___ __| | ___ (_)___
# | \| |/ _ \ / _` |/ _ \| / __|
# | |\ | (_) | (_| | __/| \__ \
# |_| \_|\___/ \__,_|\___|/ |___/
# |__/
npm_packages=(grunt-cli, gulp, gulp-cli, webpack mocha chai chai-as-promised babel
karma uglify-js react flux redux selenium-webdriver eslint typescript)
# npm scripts over grunt-cli or gulp for building
# ____ _ ____
# | _ \ _ _| |__ _ _ / ___| ___ _ __ ___ ___
# | |_) | | | | '_ \| | | | | _ / _ \ '_ ` _ \/ __|
# | _ <| |_| | |_) | |_| | |_| | __/ | | | | \__ \
# |_| \_\\__,_|_.__/ \__, |\____|\___|_| |_| |_|___/
# |___/
rubygems=(bundler gemedit guard guard-rake guard-shell hirb jekyll json json-schema
jsonpath libv8 minitest minitest-colorize minitest-context
minitest-documentation pg pry pry-byebug pry-nav pry-rails rails
rb-fsevent rb-inotify sinatra therubyracer thin thor wraith)
# ____ _ _ _____
# | _ \ _ _| |_| |__ ___ _ __ | ____|__ _ __ _ ___
# | |_) | | | | __| '_ \ / _ \| '_ \| _| / _` |/ _` / __|
# | __/| |_| | |_| | | | (_) | | | | |__| (_| | (_| \__ \
# |_| \__, |\__|_| |_|\___/|_| |_|_____\__, |\__, |___/
# |___/ |___/ |___/
python_eggs=()
# __ _ _
# / _|_ _ _ __ ___| |_(_) ___ _ __ ___
# | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# | _| |_| | | | | (__| |_| | (_) | | | \__ \
# |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#
fancy_echo() {
printf "\n%b\n" "$1"
}
append_to_zshrc() {
local text="$1" zshrc
local skip_new_line="$2"
if [[ -w "$HOME/.zshrc.local" ]]; then
zshrc="$HOME/.zshrc.local"
else
zshrc="$HOME/.zshrc"
fi
if ! grep -Fqs "$text" "$zshrc"; then
if (( skip_new_line )); then
printf "%s\n" "$text" >> "$zshrc"
else
printf "\n%s\n" "$text" >> "$zshrc"
fi
fi
}
containsElement () {
local e
array=( `echo "${@:2}"` )
for e in "${array[@]}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
update_installed_list() {
installed=$(brew list)
}
update_outdated_list() {
outdated=$(brew outdated)
}
brew_install_or_upgrade() {
if containsElement "$1" "${installed[@]}"; then
if containsElement "$1" "${outdated[@]}"; then
brew upgrade "$@"
echo " Upgraded $@"
update_outdated_list
fi
else
brew install "$@"
echo " Installed $@"
update_installed_list
fi
}
brew_launchctl_restart() {
local NAME="$1"
local DOMAIN="homebrew.mxcl.$NAME"
local PLIST="$DOMAIN.plist"
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/$NAME/$PLIST ~/Library/LaunchAgents
if launchctl list | grep -q $DOMAIN; then
launchctl unload ~/Library/LaunchAgents/$PLIST >/dev/null
fi
launchctl load ~/Library/LaunchAgents/$PLIST >/dev/null
}
echo " ___ _ _ _ "
echo "|_ _| |_ | |__ ___ __ _(_)_ __ ___ "
echo " | || __| | '_ \ / _ \/ _\` | | '_ \/ __| "
echo " | || |_ | |_) | __/ (_| | | | | \__ \_ _ _ "
echo "|___|\__| |_.__/ \___|\__, |_|_| |_|___(_|_|_) "
echo " |___/ "
echo
fancy_echo "Checking for xcode command line tools"
xcode-select --install
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
set -e
# Create ~/bin home directory for local binaries and add to path
if [[ ! -d "$HOME/bin/" ]]; then
mkdir "$HOME/bin"
fi
echo " _ _ _ "
echo " | | | | ___ _ __ ___ ___| |__ _ __ _____ __ "
echo " | |_| |/ _ \| '_ \` _ \ / _ \ '_ \| '__/ _ \ \ /\ / / "
echo " | _ | (_) | | | | | | __/ |_) | | | __/\ V V / "
echo " |_| |_|\___/|_| |_| |_|\___|_.__/|_| \___| \_/\_/ "
echo
if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew, a good OS X package manager ..."
ruby <(curl -fsS https://raw.githubusercontent.com/Homebrew/install/master/install)
else
fancy_echo "Homebrew already installed. Skipping ..."
fi
# TODO: This is already in the zshrc template append_to_zshrc 'export PATH="/usr/local/bin:$PATH"' 1
export PATH="/usr/local/bin:$PATH"
fancy_echo "Updating Homebrew formulas ..."
brew update
update_installed_list
update_outdated_list
brew_install_or_upgrade "git"
fancy_echo "Checking if brew-cask is installed ..."
if containsElement "brew-cask" "${installed[@]}"; then
if containsElement "brew-cask" "${outdated[@]}"; then
brew tap caskroom/cask
fi
else
brew tap caskroom/cask
fi
echo
echo
echo -n "Installing casks: "
export HOMEBREW_CASK_OPTS="--appdir=/Applications"
for cask in "${brew_casks[@]}"; do
echo -n "$cask..."
 if ! brew cask list -1 | grep -Fqx "$cask"; then
brew cask reinstall "$cask"
fi
done
echo -n "Installing/Updating brew formulae: "
for formula in "${brew_formulae[@]}"; do
echo -n "$formula..."
brew_install_or_upgrade $formula
done
echo
brew linkapps
# Post install steps
# fancy_echo "Starting Postgres ..."
# brew_launchctl_restart postgresql
echo " _____ _ "
echo "|__ /___| |__ "
echo " / // __| '_ \ "
echo " / /_\__ \ | | | "
echo "/____|___/_| |_| "
echo ""
brew_zsh_path=$(which zsh)
# TODO: assert that this is the brew version: i.e. not /bin/zsh
if ! grep -Fqs "$brew_zsh_path" "/etc/shells"; then
sudo sh -c "echo $brew_zsh_path >> /etc/shells"
fi
if [[ "$SHELL" != */zsh ]]; then
fancy_echo "Changing your shell to zsh ..."
chsh -s $(which zsh)
fi
# Installing oh-my-zsh
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
fancy_echo "Installing Oh My Zsh"
curl -L http://install.ohmyz.sh | sh
fi
if [[ -f "$HOME/.zshrc" ]]; then
fancy_echo "Making a backup copy of your .zshrc to .zshrc-backup"
cp ~/.zshrc ~/.zshrc-backup
fi
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
# install our preferred theme
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
# Download the font
wget https://github.com/powerline/fonts/raw/master/Meslo%20Slashed/Meslo%20LG%20M%20Regular%20for%20Powerline.ttf
# Replace the deault robbyrussell theme with our preferred theme
ZSH_THEME="powerlevel9k/powerlevel9k"
sed -E "s/robbyrussell/powerlevel9k\/powerlevel9k/" ~/.zshrc > ~/zshrc-tmp
# Replace the plugins line in the .zshrc template with this one
sed -E "s/plugins=\(git\)/plugins=(atom autoenv brew brew-cask bundler colored-man colorize docker gem git git-prompt jira jsontools node npm postgres pow rails redis-cli sublime themes vagrant virtualenv virtualenvwrapper)/" ~/.zshrc > ~/zshrc-tmp
cp ~/zshrc-tmp ~/.zshrc
rm ~/zshrc-tmp
# Append after the end of the template
append_to_zshrc '# Used for compile flags for gems' 1
append_to_zshrc 'export ARCHFLAGS="-arch x86_64"'
append_to_zshrc 'export MANPATH="$MANPATH:/usr/local/opt/erlang/lib/erlang/man"'
append_to_zshrc 'export HOMEBREW_CASK_OPTS="--appdir=/Applications"'
append_to_zshrc '# Zsh syntax highlighting' 1
append_to_zshrc 'export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/usr/local/share/zsh-syntax-highlighting/highlighters'
append_to_zshrc 'source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh'
append_to_zshrc '# Zsh completions' 1
append_to_zshrc 'fpath=(/usr/local/share/zsh-completions $fpath)'
append_to_zshrc '# Zsh help' 1
append_to_zshrc 'HELPDIR=/usr/local/share/zsh/help'
append_to_zshrc 'unalias run-help'
append_to_zshrc 'autoload run-help'
echo " _ _ _ _ "
echo " | \ | | ___ __| | ___ (_)___ "
echo " | \| |/ _ \ / _\` |/ _ \ | / __| "
echo " | |\ | (_) | (_| | __/_ | \__ \ "
echo " |_| \_|\___/ \__,_|\___(_)/ |___/ "
echo " |__/ "
node_version="stable"
fancy_echo "Installing NVM, Node.js, and NPM, for running apps and installing JavaScript packages ..."
brew_install_or_upgrade 'nvm'
append_to_zshrc 'export PATH="$PATH:/usr/local/lib/node_modules"'
if [[ ! -d "$HOME/.nvm/" ]]; then
mkdir "$HOME/.nvm"
fi
append_to_zshrc 'export NVM_DIR="$HOME/.nvm"'
append_to_zshrc 'source $(brew --prefix nvm)/nvm.sh' 1
source $(brew --prefix nvm)/nvm.sh
nvm install "$node_version"
fancy_echo "Setting $node_version as the global default nodejs..."
nvm alias default "$node_version"
# TODO: skip installed packages
# installed_pkgs=$(npm list --parseable=true --global=true)
fancy_echo "Installing Standard Npm packages ..."
echo -n "Checking packages: "
for pkg in "${npm_packages[@]}"; do
echo -n "$pkg..."
npm update -g $pkg
done
echo
echo " ____ _ "
echo " | _ \ _ _| |__ _ _ "
echo " | |_) | | | | '_ \| | | | "
echo " | _ <| |_| | |_) | |_| | "
echo " |_| \_\\__,_|_.__/ \__, | "
echo " |___/ "
append_to_zshrc 'eval "$(rbenv init - zsh)"'
eval "$(rbenv init - zsh)"
ruby_version=$(ruby-build --definitions | egrep "^\d+\.\d+\.\d+(\-p\d+)?$" | sort |tail -n 1)
if [[ -z $(rbenv versions --bare | fgrep $ruby_version) ]]; then
fancy_echo "Installing Ruby $ruby_version ..."
rbenv install -s "$ruby_version"
fi
fancy_echo "Setting $ruby_version as global default Ruby ..."
rbenv global "$ruby_version"
fancy_echo "Updating to latest Rubygems version ..."
gem update --system
installed_gems=$(gem list --no-versions)
fancy_echo "Installing Standard Rubygems ..."
echo -n "Checking gems: "
for gem in "${rubygems[@]}"; do
echo -n "$gem..."
if ! containsElement "$gem" "${installed_gems[@]}"; then
gem install $gem
echo " Installed $@"
installed_gems=$(gem list --no-versions)
fi
done
fancy_echo "Updating outdated gems"
gem update
fancy_echo "Configuring Bundler for faster, parallel gem installation ..."
number_of_cores=$(sysctl -n hw.ncpu)
bundle config --global jobs $((number_of_cores - 1))
echo " ____ _ _ "
echo "| _ \ _ _| |_| |__ ___ _ __ "
echo "| |_) | | | | __| '_ \ / _ \| '_ \ "
echo "| __/| |_| | |_| | | | (_) | | | | "
echo "|_| \__, |\__|_| |_|\___/|_| |_| "
echo " |___/ "
pip install --upgrade setuptools
pip install --upgrade pip
append_to_zshrc 'eval "$(pyenv init -)"'
append_to_zshrc 'eval "$(pyenv virtualenv-init -)"'
installed_eggs=$(pip list)
outdated_eggs=$(pip list -o)
fancy_echo "Installing Standard Python eggs ..."
echo -n "Checking eggs: "
for egg in "${python_eggs[@]}"; do
echo -n "$egg..."
if ! containsElement "$egg" "${installed_eggs[@]}"; then
if ! containsElement "$egg" "${outdated_eggs[@]}"; then
pip install --upgrade "$egg"
echo " Upgraded $egg"
outdated_eggs=$(pip list -o)
fi
else
pip install "$egg"
echo " Installed $egg"
installed_eggs=$(pip list)
fi
done
echo
echo " _ _ _ _ _ _ _ _ "
echo "| | | |___ ___ _ __ / \ __| | __| (_) |_(_) ___ _ __ ___ "
echo "| | | / __|/ _ \ '__| / _ \ / _\` |/ _\` | | __| |/ _ \| '_ \/ __| "
echo "| |_| \__ \ __/ | / ___ \ (_| | (_| | | |_| | (_) | | | \__ \ "
echo " \___/|___/\___|_| /_/ \_\__,_|\__,_|_|\__|_|\___/|_| |_|___/ "
echo
fancy_echo "Installing your personal additions from ~/.laptop.local ..."
if [[ -f ~/.laptop.local ]]; then
source ~/.laptop.local
fi