Browse Source
I chose Caffeine since it's relatively small to download. Eventually I'd like to switch this up so we bundle a dmg, zip, etc that the test suite wires in to verify that we do the Right Thing (tm) with all those file types. Probably will want to support `file://` URLs in Casks to help us for that use case.
phinze
12 years ago
4 changed files with 115 additions and 91 deletions
@ -0,0 +1,23 @@ |
|||
module Cask::Actions |
|||
def install |
|||
Cask::Installer.install(self) |
|||
end |
|||
|
|||
def linkapps |
|||
destination_path.entries.select { |f| f.basename.to_s =~ /.app$/ }.each do |app| |
|||
symlink_destination = HOME_APPS.join(app.basename) |
|||
symlink_target = destination_path.join(app) |
|||
if symlink_destination.symlink? |
|||
puts "#{symlink_destination} exists but is symlink; removing and relinking" |
|||
puts "#{symlink_destination} -> #{symlink_target}" |
|||
symlink_destination.delete |
|||
symlink_destination.make_symlink(symlink_target) |
|||
elsif symlink_destination.directory? || symlink_destination.file? |
|||
puts "#{symlink_destination} already exists and is not a symlink, not linking #{self}" |
|||
else |
|||
puts "#{symlink_destination} -> #{symlink_target}" |
|||
symlink_destination.make_symlink(symlink_target) |
|||
end |
|||
end |
|||
end |
|||
end |
@ -0,0 +1,73 @@ |
|||
class Cask::Installer |
|||
class << self |
|||
def install(cask) |
|||
downloader = CurlDownloadStrategy.new(cask.title, SoftwareSpec.new(cask.url.to_s, cask.version)) |
|||
downloaded_path = downloader.fetch |
|||
|
|||
FileUtils.mkdir_p cask.destination_path |
|||
|
|||
_with_extracted_mountpoints(downloaded_path) do |mountpoint| |
|||
puts `ditto '#{mountpoint}' '#{cask.destination_path}'` |
|||
end |
|||
|
|||
ohai "Success! #{cask} installed to #{cask.destination_path}" |
|||
end |
|||
|
|||
def _with_extracted_mountpoints(path) |
|||
if _dmg?(path) |
|||
File.open(path) do |dmg| |
|||
xml_str = `hdiutil mount -plist -nobrowse -readonly -noidme -mountrandom /tmp '#{dmg.path}'` |
|||
hdiutil_info = Plist::parse_xml(xml_str) |
|||
raise Exception.new("No disk entities returned by mount at #{dmg.path}") unless hdiutil_info.has_key?("system-entities") |
|||
mounts = hdiutil_info["system-entities"].collect { |entity| |
|||
entity["mount-point"] |
|||
}.compact |
|||
begin |
|||
mounts.each do |mountpoint| |
|||
yield Pathname.new(mountpoint) |
|||
end |
|||
ensure |
|||
mounts.each do |mountpoint| |
|||
`hdiutil eject '#{mountpoint}'` |
|||
end |
|||
end |
|||
end |
|||
elsif _zip?(path) |
|||
destdir = "/tmp/brewcask_#{@title}_extracted" |
|||
`mkdir -p '#{destdir}'` |
|||
`unzip -d '#{destdir}' '#{path}'` |
|||
begin |
|||
yield destdir |
|||
ensure |
|||
`rm -rf '#{destdir}'` |
|||
end |
|||
elsif _tar_bzip?(path) |
|||
destdir = "/tmp/brewcask_#{@title}_extracted" |
|||
`mkdir -p '#{destdir}'` |
|||
`tar jxf '#{path}' -C '#{destdir}'` |
|||
begin |
|||
yield destdir |
|||
ensure |
|||
`rm -rf '#{destdir}'` |
|||
end |
|||
else |
|||
raise "uh oh, could not identify type of #{path}" |
|||
end |
|||
end |
|||
|
|||
def _dmg?(path) |
|||
output = `hdiutil imageinfo '#{path}' 2>/dev/null` |
|||
output != '' |
|||
end |
|||
|
|||
def _zip?(path) |
|||
output = `file -Izb '#{path}'` |
|||
output.chomp.include? 'compressed-encoding=application/zip; charset=binary; charset=binary' |
|||
end |
|||
|
|||
def _tar_bzip?(path) |
|||
output = `file -Izb '#{path}'` |
|||
output.chomp == 'application/x-tar; charset=binary compressed-encoding=application/x-bzip2; charset=binary; charset=binary' |
|||
end |
|||
end |
|||
end |
Loading…
Reference in new issue