2013-07-27 02:54:40 +08:00
|
|
|
HOMEBREW_CACHE_CASKS = HOMEBREW_CACHE.join('Casks')
|
|
|
|
|
2012-03-05 10:46:30 +08:00
|
|
|
class Cask; end
|
|
|
|
|
2014-01-11 00:42:18 +08:00
|
|
|
require 'download_strategy'
|
|
|
|
|
2014-05-04 00:39:16 +08:00
|
|
|
# transitional, for set_up_taps (see below)
|
|
|
|
require 'cmd/update'
|
2014-05-06 21:37:17 +08:00
|
|
|
require 'rubygems'
|
2014-05-04 00:39:16 +08:00
|
|
|
|
2013-09-23 22:32:46 +08:00
|
|
|
require 'cask/artifact'
|
2013-09-22 10:44:49 +08:00
|
|
|
require 'cask/audit'
|
|
|
|
require 'cask/auditor'
|
2013-12-06 09:38:23 +08:00
|
|
|
require 'cask/without_source'
|
2013-09-22 10:44:49 +08:00
|
|
|
require 'cask/checkable'
|
|
|
|
require 'cask/cli'
|
2014-01-15 06:41:11 +08:00
|
|
|
require 'cask/caveats'
|
2013-09-22 10:44:49 +08:00
|
|
|
require 'cask/container'
|
|
|
|
require 'cask/download'
|
2013-12-06 03:26:56 +08:00
|
|
|
require 'cask/download_strategy'
|
2013-09-22 10:44:49 +08:00
|
|
|
require 'cask/dsl'
|
|
|
|
require 'cask/exceptions'
|
|
|
|
require 'cask/fetcher'
|
|
|
|
require 'cask/installer'
|
|
|
|
require 'cask/link_checker'
|
2013-09-23 22:32:46 +08:00
|
|
|
require 'cask/locations'
|
2014-01-06 04:30:53 +08:00
|
|
|
require 'cask/options'
|
2013-09-22 10:44:49 +08:00
|
|
|
require 'cask/pkg'
|
2013-11-04 02:23:08 +08:00
|
|
|
require 'cask/pretty_listing'
|
2014-01-04 20:14:35 +08:00
|
|
|
require 'cask/qualified_cask_name'
|
2013-09-22 10:44:49 +08:00
|
|
|
require 'cask/scopes'
|
2013-11-17 03:40:51 +08:00
|
|
|
require 'cask/source'
|
2013-09-22 10:44:49 +08:00
|
|
|
require 'cask/system_command'
|
2013-09-22 06:07:19 +08:00
|
|
|
require 'cask/underscore_supporting_uri'
|
2013-12-16 03:18:47 +08:00
|
|
|
require 'cask/url'
|
2014-01-23 07:29:00 +08:00
|
|
|
require 'cask/utils'
|
2014-01-29 23:00:13 +08:00
|
|
|
require 'cask/version'
|
2013-09-22 10:44:49 +08:00
|
|
|
|
|
|
|
require 'plist/parser'
|
2012-03-05 10:46:30 +08:00
|
|
|
|
|
|
|
class Cask
|
2012-10-14 05:30:59 +08:00
|
|
|
include Cask::DSL
|
2013-09-23 22:32:46 +08:00
|
|
|
include Cask::Locations
|
2012-10-14 05:48:25 +08:00
|
|
|
include Cask::Scopes
|
2014-01-06 04:30:53 +08:00
|
|
|
include Cask::Options
|
2012-10-14 05:17:52 +08:00
|
|
|
|
2012-03-05 10:46:30 +08:00
|
|
|
def self.init
|
2014-05-04 00:39:16 +08:00
|
|
|
set_up_taps
|
2014-01-23 07:29:00 +08:00
|
|
|
odebug 'Creating directories'
|
2012-10-16 08:25:35 +08:00
|
|
|
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?
|
2014-02-05 22:57:35 +08:00
|
|
|
HOMEBREW_CACHE_CASKS.mkpath unless HOMEBREW_CACHE_CASKS.exist?
|
2013-04-07 06:14:04 +08:00
|
|
|
unless caskroom.exist?
|
|
|
|
ohai "We need to make Caskroom for the first time at #{caskroom}"
|
2013-05-27 23:35:44 +08:00
|
|
|
ohai "We'll set permissions properly so we won't need sudo in the future"
|
2014-02-21 22:30:37 +08:00
|
|
|
current_user = Etc.getpwuid(Process.euid).name
|
2014-01-09 03:22:32 +08:00
|
|
|
if caskroom.parent.writable?
|
2014-01-25 01:59:17 +08:00
|
|
|
system '/bin/mkdir', caskroom
|
2014-01-09 03:22:32 +08:00
|
|
|
else
|
2014-05-07 22:56:04 +08:00
|
|
|
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
|
2014-01-09 03:22:32 +08:00
|
|
|
# sudo in system is rude.
|
2014-01-25 09:40:38 +08:00
|
|
|
system '/usr/bin/sudo', '--', '/bin/mkdir', '-p', '--', caskroom
|
2014-05-07 22:56:04 +08:00
|
|
|
unless caskroom.parent == toplevel_dir
|
|
|
|
system '/usr/bin/sudo', '--', '/usr/sbin/chown', '-R', '--', "#{current_user}:staff", caskroom.parent
|
|
|
|
end
|
2014-01-09 03:22:32 +08:00
|
|
|
end
|
2013-04-07 06:14:04 +08:00
|
|
|
end
|
2012-03-05 10:46:30 +08:00
|
|
|
end
|
|
|
|
|
2014-05-04 00:39:16 +08:00
|
|
|
def self.set_up_taps
|
|
|
|
odebug 'Initializing Taps'
|
|
|
|
|
2014-05-06 21:37:17 +08:00
|
|
|
return true if Cask.default_tap.match(%r{test[^/]*\Z})
|
|
|
|
|
2014-05-04 00:39:16 +08:00
|
|
|
# transitional: help with Homebrew's move of Tap dirs, Apr 2014
|
2014-05-06 21:37:17 +08:00
|
|
|
minimum_homebrew_version = '0.9.5'
|
|
|
|
unless Gem::Version.new(HOMEBREW_VERSION) >= Gem::Version.new(minimum_homebrew_version)
|
|
|
|
raise CaskError.new <<-EOS.undent
|
|
|
|
Minimum Homebrew version '#{minimum_homebrew_version}' required.
|
|
|
|
(Homebrew version #{HOMEBREW_VERSION} was detected.)
|
|
|
|
Try running "brew update".
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
Homebrew.send(:rename_taps_dir_if_necessary)
|
|
|
|
rescue StandardError
|
|
|
|
opoo %q{Trouble with automatic Tap migration. You may need to run "brew update && brew upgrade brew-cask"}
|
|
|
|
end
|
2014-05-04 00:39:16 +08:00
|
|
|
|
|
|
|
# transitional: help with our own move to new GitHub project, May 2014
|
|
|
|
legacy_user = 'phinze'
|
|
|
|
new_user = 'caskroom'
|
|
|
|
repo = 'cask'
|
|
|
|
legacy_tap = HOMEBREW_LIBRARY/"Taps/#{legacy_user}/homebrew-#{repo}"
|
|
|
|
new_tap = HOMEBREW_LIBRARY/"Taps/#{new_user}/homebrew-#{repo}"
|
|
|
|
if legacy_tap.directory?
|
|
|
|
ohai 'Removing legacy Tap'
|
|
|
|
files = []
|
|
|
|
legacy_tap.find_formula { |file| files << file }
|
|
|
|
Homebrew.unlink_tap_formula(files)
|
|
|
|
legacy_tap.rmtree
|
|
|
|
legacy_tap.dirname.rmdir_if_possible
|
|
|
|
end
|
|
|
|
unless new_tap.directory?
|
|
|
|
ohai 'Adding caskroom Tap'
|
|
|
|
Homebrew.install_tap(new_user, repo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-17 03:40:51 +08:00
|
|
|
def self.load(query)
|
2014-01-23 07:29:00 +08:00
|
|
|
odebug 'Loading Cask definitions'
|
|
|
|
cask = Cask::Source.for_query(query).load
|
|
|
|
odumpcask cask
|
|
|
|
cask
|
2012-03-05 10:46:30 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.title
|
2012-12-18 07:59:58 +08:00
|
|
|
self.name.gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').downcase
|
2012-03-05 10:46:30 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :title
|
|
|
|
def initialize(title=self.class.title)
|
|
|
|
@title = title
|
|
|
|
end
|
|
|
|
|
2013-11-11 04:48:16 +08:00
|
|
|
def caskroom_path
|
2013-12-06 09:38:23 +08:00
|
|
|
self.class.caskroom.join(title)
|
2013-11-11 04:48:16 +08:00
|
|
|
end
|
|
|
|
|
2012-03-05 10:46:30 +08:00
|
|
|
def destination_path
|
2013-12-06 09:38:23 +08:00
|
|
|
caskroom_path.join(version)
|
2012-03-05 10:46:30 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
2012-10-21 02:34:11 +08:00
|
|
|
destination_path.exist?
|
2012-03-05 10:46:30 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
@title
|
|
|
|
end
|
|
|
|
end
|