homebrew-cask/lib/hbc.rb

90 lines
2.6 KiB
Ruby
Raw Normal View History

HOMEBREW_CACHE_CASKS = HOMEBREW_CACHE.join('Casks')
module Hbc; end
require 'hbc/extend'
require 'hbc/artifact'
require 'hbc/audit'
require 'hbc/auditor'
require 'hbc/cask'
require 'hbc/without_source'
require 'hbc/checkable'
require 'hbc/cli'
require 'hbc/cask_dependencies'
require 'hbc/caveats'
require 'hbc/container'
require 'hbc/download'
require 'hbc/download_strategy'
require 'hbc/exceptions'
require 'hbc/fetcher'
require 'hbc/hardware'
require 'hbc/installer'
require 'hbc/locations'
require 'hbc/macos'
require 'hbc/options'
require 'hbc/pkg'
require 'hbc/pretty_listing'
require 'hbc/qualified_token'
require 'hbc/scopes'
require 'hbc/source'
require 'hbc/staged'
require 'hbc/system_command'
require 'hbc/topological_hash'
require 'hbc/underscore_supporting_uri'
require 'hbc/url'
require 'hbc/url_checker'
require 'hbc/utils'
require 'hbc/verify'
require 'hbc/version'
naked pkg support + major container refactor `Cask::Installer` was already much too complex, so I took this opportunity to throw a `Cask::Container` abstraction around the extraction part of the package install step. It goes like this: a Cask's URL points to a Container of some sort. The containers we currently support are: dmg, zip, tar, and (new) naked. Naked refers to a raw file that just needs to be copied in place. This currently just means a pkg file, but in the future it may expand. A Container knows how to do two things: identify a path as being its type (`Container.me?`) and extracting the contents of its container to the proper destination for a Cask (`Container#extract`). The first Cask we have that supports the naked pkg type is `heroku-toolbelt`. (Thanks to @sheerun for the Cask definition.) Other miscellania batched in with this refactor: - switched to an explicit require strategy rather than globbing - `Cask::Installer` is instantiated now to match its interface with other similar collaorators - simplified zip and tar identification to shorter strings rather than exact matches of full `file -Izb` output - `Cask::SystemCommand` gets explicit output redirection options - many rogue backticks replaced to properly use `SystemCommand` - fixed misnamed test file `link_checker_spec.rb` - remove some extraneous `after` clauses in tests; leaning more on `test/support/cleanup.rb` to uninstall for us - pkg uninstall `:files` gets a `-rf` to support removing dirs refs #839 and #1043
2013-09-22 10:44:49 +08:00
2014-12-21 02:23:10 +08:00
require 'vendor/plist'
module Hbc
include Hbc::Locations
include Hbc::Scopes
include Hbc::Options
include Hbc::Utils
# todo: restrict visibility of this to the DSL
::MacOS = Hbc::MacOS
::Hardware = Hbc::Hardware
def self.init
2014-10-04 20:23:28 +08:00
# todo: Creating directories should be deferred until needed.
# Currently this fire and even asks for sudo password
# if a first-time user simply runs "brew cask --help".
odebug 'Creating directories'
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?
HOMEBREW_CACHE_CASKS.mkpath unless HOMEBREW_CACHE_CASKS.exist?
unless caskroom.exist?
ohai "We need to make Caskroom for the first time at #{caskroom}"
ohai "We'll set permissions properly so we won't need sudo in the future"
current_user = Etc.getpwuid(Process.euid).name
if caskroom.parent.writable?
2014-09-10 01:16:44 +08:00
system '/bin/mkdir', '--', caskroom
else
toplevel_dir = caskroom
toplevel_dir = toplevel_dir.parent until toplevel_dir.parent.root?
unless toplevel_dir.directory?
# If a toplevel dir such as '/opt' must be created, enforce standard permissions.
# sudo in system is rude.
system '/usr/bin/sudo', '--', '/bin/mkdir', '--', toplevel_dir
system '/usr/bin/sudo', '--', '/bin/chmod', '--', '0775', toplevel_dir
end
# sudo in system is rude.
system '/usr/bin/sudo', '--', '/bin/mkdir', '-p', '--', caskroom
unless caskroom.parent == toplevel_dir
system '/usr/bin/sudo', '--', '/usr/sbin/chown', '-R', '--', "#{current_user}:staff", caskroom.parent.to_s
end
end
end
end
def self.load(query)
odebug 'Loading Cask definitions'
cask = Hbc::Source.for_query(query).load
cask.dumpcask
cask
end
end