Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Rewrite setup file using Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
lenon committed Nov 29, 2015
1 parent bda8a20 commit d9d3372
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 57 deletions.
11 changes: 11 additions & 0 deletions osx/casks
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
adium
alfred
dropbox
flux
iterm2
macvim
1password
spectacle
spotify
the-unarchiver
transmission
8 changes: 8 additions & 0 deletions osx/packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
caskroom/cask/brew-cask
vim
git
ag
tmux
openssl
python
tree
111 changes: 111 additions & 0 deletions osx/setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env ruby

def info(str)
STDERR.puts str
end

module OS
module_function

def mac?
RUBY_PLATFORM.downcase.include? 'darwin'
end
end

module Homebrew
module_function

def installed?
system 'command -v brew >/dev/null 2>&1'
end

def install
system 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
end

def pkg_installed?(pkg)
system "brew list #{pkg} >/dev/null 2>&1"
end

def install_pkg(pkg)
system "brew install #{pkg}"
end

def cleanup
system 'brew cleanup >/dev/null 2>&1'
end
end

module Cask
module_function

def pkg_installed?(pkg)
system "brew cask list #{pkg} >/dev/null 2>&1"
end

def install_pkg(pkg)
system "brew cask install --appdir=/Applications #{pkg}"
end

def cleanup
system 'brew cask cleanup >/dev/null 2>&1'
end
end

unless OS.mac?
abort 'This script only works on Mac OS X'
end

if Homebrew.installed?
info 'Homebrew is already installed, skipping'
else
info 'Installing Homebrew...'

if Homebrew.install
info 'Homebrew installed'
else
abort 'Homebrew was not installed due to a problem'
end
end

packages = File.readlines('packages').map(&:strip)
casks = File.readlines('casks').map(&:strip)

info 'Installing Homebrew packages...'

packages.each do |pkg|
if Homebrew.pkg_installed?(pkg)
info "#{pkg} is already installed, skipping"
else
info "Installing #{pkg}"

if Homebrew.install_pkg(pkg) && Homebrew.pkg_installed?(pkg)
info "#{pkg} installed"
else
abort "#{pkg} was not installed due to a problem"
end
end
end

info 'Installing cask packages...'

casks.each do |pkg|
if Cask.pkg_installed?(pkg)
info "#{pkg} is already installed, skipping"
else
info "Installing #{pkg}"

if Cask.install_pkg(pkg) && Cask.pkg_installed?(pkg)
info "#{pkg} installed"
else
abort "#{pkg} was not installed due to a problem"
end
end
end

info 'Cleaning old packages...'

Homebrew.cleanup
Cask.cleanup

info 'Done!'
57 changes: 0 additions & 57 deletions osx/setup.sh

This file was deleted.

0 comments on commit d9d3372

Please sign in to comment.