2014-06-15 22:24:05 -07:00
|
|
|
require_relative 'sh'
|
|
|
|
|
2014-04-11 00:31:44 -07:00
|
|
|
include Rake::DSL
|
|
|
|
|
|
|
|
module Homebrew
|
2014-08-30 23:50:03 -07:00
|
|
|
BIN = "/usr/local/bin/brew"
|
|
|
|
|
|
|
|
def self.bootstrap
|
|
|
|
unless self.is_installed?
|
|
|
|
sh_safe 'ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"'
|
|
|
|
echo "Homebrew is installed! Restart the shell then rake."
|
|
|
|
exit
|
2014-04-11 00:31:44 -07:00
|
|
|
end
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.destroy
|
|
|
|
if self.is_installed?
|
|
|
|
sh_safe 'rm -rf /usr/local/Cellar /usr/local/.git ~/Library/Caches/Homebrew'
|
|
|
|
sh_safe 'brew prune'
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
['Library/Homebrew', 'Library/Aliases', 'Library/Formula', 'Library/Contributions'].each do |dir|
|
|
|
|
sh_safe "rm -r #{dir}"
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
end
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.install(keg, options=nil)
|
|
|
|
sh_safe "#{BIN} install #{keg} #{options}" unless self.is_keg_installed?(keg)
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.install_cask(cask, options=nil)
|
|
|
|
sh_safe "#{BIN} cask install #{cask} #{options}" unless self.is_cask_installed?(cask)
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.tap(tap)
|
|
|
|
sh_safe "#{BIN} tap #{tap}" unless self.is_tapped? tap
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.remove(keg)
|
|
|
|
sh_safe "#{BIN} remove #{keg}"
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.remove_cask(keg)
|
|
|
|
sh_safe "#{BIN} cask uninstall #{keg}"
|
|
|
|
end
|
2014-07-17 05:11:18 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.has_keg?(keg)
|
|
|
|
system("#{BIN} search #{keg}")
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.is_keg_installed?(keg)
|
|
|
|
system("#{BIN} list | grep -w '#{keg}' >& /dev/null")
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.is_cask_installed?(cask)
|
|
|
|
system("#{BIN} cask list | grep -w '#{cask}' >& /dev/null")
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.is_tapped?(tap)
|
|
|
|
system("#{BIN} tap | grep -w '#{tap}' >& /dev/null")
|
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.is_installed?
|
|
|
|
File.exists?("/usr/local/bin/brew")
|
|
|
|
end
|
2014-04-13 08:45:53 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.prefix(keg)
|
|
|
|
`#{BIN} --prefix #{keg}`.strip
|
|
|
|
end
|
2014-04-13 08:45:53 -07:00
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
def self.update(*args)
|
|
|
|
if args.length > 0
|
|
|
|
sh_safe "#{BIN} upgrade #{args.join(' ')}"
|
|
|
|
else
|
|
|
|
sh_safe "#{BIN} update && #{BIN} upgrade"
|
2014-04-11 00:31:44 -07:00
|
|
|
end
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|
2014-04-11 00:31:44 -07:00
|
|
|
end
|