helm/rake/lib/homebrew.rb

72 lines
1.7 KiB
Ruby
Raw Normal View History

2014-04-11 00:31:44 -07:00
include Rake::DSL
module Homebrew
BIN = "/usr/local/bin/brew"
def self.bootstrap
unless self.is_installed?
sh 'ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"'
sh 'exec $SHELL -l'
end
end
def self.destroy
if self.is_installed?
sh 'rm -rf /usr/local/Cellar /usr/local/.git ~/Library/Caches/Homebrew'
sh 'brew prune'
['Library/Homebrew', 'Library/Aliases', 'Library/Formula', 'Library/Contributions'].each do |dir|
sh "rm -r #{dir}"
end
end
end
def self.install(keg, options=nil)
sh "#{BIN} install #{keg} #{options}" unless self.is_keg_installed?(keg)
end
def self.install_cask(cask, options=nil)
sh "#{BIN} cask install #{cask} #{options}" unless self.is_cask_installed?(cask)
end
def self.tap(tap)
sh "#{BIN} tap #{tap}" unless self.is_tapped? tap
end
def self.remove(keg)
sh "#{BIN} remove #{keg}"
end
def self.has_keg?(keg)
2014-04-13 08:45:53 -07:00
`#{BIN} search #{keg}`
2014-04-11 00:31:44 -07:00
end
def self.is_keg_installed?(keg)
2014-04-13 08:45:53 -07:00
`#{BIN} list | grep -w '#{keg}'`
2014-04-11 00:31:44 -07:00
end
def self.is_cask_installed?(cask)
2014-04-13 08:45:53 -07:00
`#{BIN} cask list | grep -w '#{cask}'`
2014-04-11 00:31:44 -07:00
end
def self.is_tapped?(tap)
2014-04-13 08:45:53 -07:00
`#{BIN} tap | grep -w '#{tap}'`
2014-04-11 00:31:44 -07:00
end
def self.is_installed?
2014-04-13 08:45:53 -07:00
File.exists?("/usr/local/bin/brew")
2014-04-11 00:31:44 -07:00
end
2014-04-13 08:45:53 -07:00
def self.prefix(keg)
`#{BIN} --prefix #{keg}`.strip
end
def self.update(*args)
if args.length > 0
sh "#{BIN} upgrade #{args.join(' ')}"
else
sh "#{BIN} update && #{BIN} upgrade"
end
2014-04-11 00:31:44 -07:00
end
end