Skip to content

Instantly share code, notes, and snippets.

@odlp
Created November 5, 2015 16:01
Show Gist options
  • Save odlp/26afe3f10e46eca4e904 to your computer and use it in GitHub Desktop.
Save odlp/26afe3f10e46eca4e904 to your computer and use it in GitHub Desktop.
Brewstrap: Taps the taps, installs the formulae & casks
#!/usr/bin/env ruby
require 'yaml'
CONFIG_FILE_NAME = 'brewstrap.yml'
COMMAND_INSTALL_CASK = 'brew install caskroom/cask/brew-cask'
COMMAND_BREW_UPDATE = 'brew update'
COMMAND_FORMULA_INSTALL = 'brew install'
COMMAND_BREW_TAP = 'brew tap'
COMMAND_BREW_CASK_INSTALL = 'brew cask install --appdir=/Applications'
def perform_command(command)
puts "Performing command: #{command}"
IO.popen(command) do |io|
while (line = io.gets) do
puts line
end
end
end
def perform_command_per_item(items, command)
items.each{ |item| perform_command("#{command} #{item}") }
end
def check_for_homebrew!
puts "Checking for homebrew\n"
if system('brew --version')
puts "Homebrew installed...\n"
else
puts 'Please install Homebrew! Run the following command:'
puts 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
abort "Exiting..."
end
puts
end
def install_cask_if_needed
puts "Checking for brew cask\n"
if system('brew cask --version')
puts "Brew cask installed...\n"
else
puts "Installing brew cask...\n"
perform_command(COMMAND_INSTALL_CASK)
end
puts
end
def load_config
abort "Cannot find #{CONFIG_FILE_NAME}" unless File.exist?(CONFIG_FILE_NAME)
YAML.load_file(CONFIG_FILE_NAME)
end
check_for_homebrew!
install_cask_if_needed
perform_command(COMMAND_BREW_UPDATE)
config = load_config
taps = config.fetch('taps', [])
formulae = config.fetch('formulae', [])
casks = config.fetch('casks', [])
puts "\nInstalling taps...\n"
perform_command_per_item(taps, COMMAND_BREW_TAP)
puts "\nInstalling formulae...\n"
perform_command_per_item(formulae, COMMAND_FORMULA_INSTALL)
puts "\nInstalling casks...\n"
perform_command_per_item(casks, COMMAND_BREW_CASK_INSTALL)
taps:
- git-duet/tap
formulae:
- ssh-copy-id
- tmux
- tree
- wget
- rbenv
- rbenv-gem-rehash
- git-duet
casks:
- iterm2
- appcode
- atom
- textmate
- sublime-text
- flycut
- shiftit
- bettertouchtool
- google-chrome
- firefox
- google-hangouts
- screenhero
- xquartz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment