2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-28 17:53:59 +02:00
|
|
|
require "formula_installer"
|
2018-07-23 23:04:49 +02:00
|
|
|
require "unpack_strategy"
|
2017-06-28 17:53:59 +02:00
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
require "cask/topological_hash"
|
2019-02-03 13:03:16 +01:00
|
|
|
require "cask/config"
|
2018-09-03 19:39:07 +01:00
|
|
|
require "cask/download"
|
|
|
|
require "cask/staged"
|
|
|
|
require "cask/quarantine"
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-07-16 20:22:37 +02:00
|
|
|
require "cgi"
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2020-08-24 23:33:12 +02:00
|
|
|
# Installer for a {Cask}.
|
|
|
|
#
|
|
|
|
# @api private
|
2016-09-24 13:52:43 +02:00
|
|
|
class Installer
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2017-06-26 07:30:28 +02:00
|
|
|
extend Predicable
|
2018-09-06 08:29:14 +02:00
|
|
|
# TODO: it is unwise for Cask::Staged to be a module, when we are
|
2020-11-05 17:17:03 -05:00
|
|
|
# dealing with both staged and unstaged casks here. This should
|
2016-09-24 13:52:43 +02:00
|
|
|
# either be a class which is only sometimes instantiated, or there
|
|
|
|
# should be explicit checks on whether staged state is valid in
|
|
|
|
# every method.
|
|
|
|
include Staged
|
|
|
|
|
2018-08-31 13:16:11 +00:00
|
|
|
def initialize(cask, command: SystemCommand, force: false,
|
|
|
|
skip_cask_deps: false, binaries: true, verbose: false,
|
|
|
|
require_sha: false, upgrade: false,
|
2020-12-04 00:07:02 +01:00
|
|
|
installed_as_dependency: false, quarantine: true,
|
|
|
|
verify_download_integrity: true)
|
2016-09-24 13:52:43 +02:00
|
|
|
@cask = cask
|
|
|
|
@command = command
|
|
|
|
@force = force
|
|
|
|
@skip_cask_deps = skip_cask_deps
|
2017-05-19 19:13:23 +02:00
|
|
|
@binaries = binaries
|
2017-05-21 00:15:56 +02:00
|
|
|
@verbose = verbose
|
2016-09-24 13:52:43 +02:00
|
|
|
@require_sha = require_sha
|
2017-03-27 01:31:29 -05:00
|
|
|
@reinstall = false
|
2017-10-29 17:31:07 -03:00
|
|
|
@upgrade = upgrade
|
2018-07-14 03:25:42 +02:00
|
|
|
@installed_as_dependency = installed_as_dependency
|
2018-08-31 13:16:11 +00:00
|
|
|
@quarantine = quarantine
|
2020-12-04 00:07:02 +01:00
|
|
|
@verify_download_integrity = verify_download_integrity
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-08-31 13:16:11 +00:00
|
|
|
attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?,
|
2019-02-02 17:11:37 +01:00
|
|
|
:reinstall?, :upgrade?, :verbose?, :installed_as_dependency?,
|
2018-08-31 13:16:11 +00:00
|
|
|
:quarantine?
|
2017-05-21 00:15:56 +02:00
|
|
|
|
2019-03-11 21:20:02 -04:00
|
|
|
def self.caveats(cask)
|
2016-09-24 13:52:43 +02:00
|
|
|
odebug "Printing caveats"
|
2016-10-24 17:07:57 +02:00
|
|
|
|
2017-11-24 17:44:01 +01:00
|
|
|
caveats = cask.caveats
|
|
|
|
return if caveats.empty?
|
2016-10-24 17:07:57 +02:00
|
|
|
|
2019-02-24 21:53:04 -05:00
|
|
|
<<~EOS
|
|
|
|
#{ohai_title "Caveats"}
|
|
|
|
#{caveats}
|
|
|
|
EOS
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-12-04 23:13:39 +01:00
|
|
|
def fetch
|
2018-09-06 08:29:14 +02:00
|
|
|
odebug "Cask::Installer#fetch"
|
2016-12-04 23:13:39 +01:00
|
|
|
|
2017-06-26 07:30:28 +02:00
|
|
|
verify_has_sha if require_sha? && !force?
|
2020-09-02 18:14:24 +06:00
|
|
|
satisfy_dependencies
|
|
|
|
|
2016-12-04 23:13:39 +01:00
|
|
|
download
|
|
|
|
end
|
|
|
|
|
|
|
|
def stage
|
2018-09-06 08:29:14 +02:00
|
|
|
odebug "Cask::Installer#stage"
|
2016-12-04 23:13:39 +01:00
|
|
|
|
2018-06-09 11:18:40 +02:00
|
|
|
Caskroom.ensure_caskroom_exists
|
|
|
|
|
2016-12-04 23:13:39 +01:00
|
|
|
extract_primary_container
|
|
|
|
save_caskfile
|
2018-09-02 20:14:54 +01:00
|
|
|
rescue => e
|
2016-12-04 23:13:39 +01:00
|
|
|
purge_versioned_files
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def install
|
2018-09-06 08:29:14 +02:00
|
|
|
odebug "Cask::Installer#install"
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2019-02-03 13:03:16 +01:00
|
|
|
old_config = @cask.config
|
|
|
|
|
2019-02-19 13:11:32 +00:00
|
|
|
raise CaskAlreadyInstalledError, @cask if @cask.installed? && !force? && !reinstall? && !upgrade?
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-08-05 15:56:34 +02:00
|
|
|
check_conflicts
|
|
|
|
|
2019-03-11 21:20:02 -04:00
|
|
|
print caveats
|
2016-12-04 23:13:39 +01:00
|
|
|
fetch
|
2019-02-02 17:11:37 +01:00
|
|
|
uninstall_existing_cask if reinstall?
|
2017-03-18 18:57:04 -05:00
|
|
|
|
2019-10-24 15:15:40 +02:00
|
|
|
backup if force? && @cask.staged_path.exist? && @cask.metadata_versioned_path.exist?
|
|
|
|
|
2018-02-09 11:31:51 +09:00
|
|
|
oh1 "Installing Cask #{Formatter.identifier(@cask)}"
|
2018-08-31 13:16:11 +00:00
|
|
|
opoo "macOS's Gatekeeper has been disabled for this Cask" unless quarantine?
|
2016-12-04 23:13:39 +01:00
|
|
|
stage
|
2019-02-03 13:03:16 +01:00
|
|
|
|
2020-09-29 23:46:30 +02:00
|
|
|
@cask.config = @cask.default_config.merge(old_config)
|
2019-02-03 13:03:16 +01:00
|
|
|
|
2016-12-04 23:13:39 +01:00
|
|
|
install_artifacts
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2019-02-19 13:11:32 +00:00
|
|
|
::Utils::Analytics.report_event("cask_install", @cask.token) unless @cask.tap&.private?
|
2018-08-06 12:21:48 -07:00
|
|
|
|
2019-10-24 15:15:40 +02:00
|
|
|
purge_backed_up_versioned_files
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
puts summary
|
2019-10-24 15:15:40 +02:00
|
|
|
rescue
|
|
|
|
restore_backup
|
|
|
|
raise
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-08-05 15:56:34 +02:00
|
|
|
def check_conflicts
|
|
|
|
return unless @cask.conflicts_with
|
|
|
|
|
2019-01-27 21:34:24 +01:00
|
|
|
@cask.conflicts_with[:cask].each do |conflicting_cask|
|
2020-12-22 15:32:05 -08:00
|
|
|
if (match = conflicting_cask.match(HOMEBREW_TAP_CASK_REGEX))
|
|
|
|
conflicting_cask_tap = Tap.fetch(match[1], match[2])
|
|
|
|
next unless conflicting_cask_tap.installed?
|
|
|
|
end
|
|
|
|
|
2019-10-13 10:03:26 +01:00
|
|
|
conflicting_cask = CaskLoader.load(conflicting_cask)
|
|
|
|
raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed?
|
|
|
|
rescue CaskUnavailableError
|
|
|
|
next # Ignore conflicting Casks that do not exist.
|
2017-08-05 15:56:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-27 01:31:29 -05:00
|
|
|
def reinstall
|
2018-09-06 08:29:14 +02:00
|
|
|
odebug "Cask::Installer#reinstall"
|
2017-03-27 01:31:29 -05:00
|
|
|
@reinstall = true
|
|
|
|
install
|
|
|
|
end
|
|
|
|
|
2017-04-17 17:21:02 -07:00
|
|
|
def uninstall_existing_cask
|
|
|
|
return unless @cask.installed?
|
2017-03-18 17:48:20 -05:00
|
|
|
|
|
|
|
# use the same cask file that was used for installation, if possible
|
2017-04-17 17:21:02 -07:00
|
|
|
installed_caskfile = @cask.installed_caskfile
|
2017-10-07 15:58:49 +02:00
|
|
|
installed_cask = installed_caskfile.exist? ? CaskLoader.load(installed_caskfile) : @cask
|
2017-03-18 17:48:20 -05:00
|
|
|
|
|
|
|
# Always force uninstallation, ignore method parameter
|
2021-02-22 19:43:30 -08:00
|
|
|
Installer.new(installed_cask, verbose: verbose?, force: true, upgrade: upgrade?).uninstall
|
2017-03-18 17:48:20 -05:00
|
|
|
end
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(String) }
|
2016-09-24 13:52:43 +02:00
|
|
|
def summary
|
2019-04-20 14:07:29 +09:00
|
|
|
s = +""
|
2020-04-05 15:44:50 +01:00
|
|
|
s << "#{Homebrew::EnvConfig.install_badge} " unless Homebrew::EnvConfig.no_emoji?
|
2017-11-06 21:27:02 -03:00
|
|
|
s << "#{@cask} was successfully #{upgrade? ? "upgraded" : "installed"}!"
|
2019-04-20 14:07:29 +09:00
|
|
|
s.freeze
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2020-12-21 15:43:25 +01:00
|
|
|
sig { returns(Download) }
|
|
|
|
def downloader
|
|
|
|
@downloader ||= Download.new(@cask, quarantine: quarantine?)
|
|
|
|
end
|
|
|
|
|
2020-12-04 00:07:02 +01:00
|
|
|
sig { returns(Pathname) }
|
2016-09-24 13:52:43 +02:00
|
|
|
def download
|
2020-12-21 15:43:25 +01:00
|
|
|
@download ||= downloader.fetch(verify_download_integrity: @verify_download_integrity)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def verify_has_sha
|
|
|
|
odebug "Checking cask has checksum"
|
|
|
|
return unless @cask.sha256 == :no_check
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2020-11-19 19:44:23 +01:00
|
|
|
raise CaskError, <<~EOS
|
|
|
|
Cask '#{@cask}' does not have a sha256 checksum defined and was not installed.
|
|
|
|
This means you have the #{Formatter.identifier("--require-sha")} option set, perhaps in your HOMEBREW_CASK_OPTS.
|
|
|
|
EOS
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-07-14 03:25:42 +02:00
|
|
|
def primary_container
|
|
|
|
@primary_container ||= begin
|
2020-12-04 00:07:02 +01:00
|
|
|
downloaded_path = download
|
|
|
|
UnpackStrategy.detect(downloaded_path, type: @cask.container&.type, merge_xattrs: true)
|
2016-10-14 20:11:33 +02:00
|
|
|
end
|
2018-07-14 03:25:42 +02:00
|
|
|
end
|
|
|
|
|
2020-12-04 00:07:02 +01:00
|
|
|
def extract_primary_container(to: @cask.staged_path)
|
2018-07-14 03:25:42 +02:00
|
|
|
odebug "Extracting primary container"
|
2016-12-04 23:13:39 +01:00
|
|
|
|
2020-12-04 00:07:02 +01:00
|
|
|
odebug "Using container class #{primary_container.class} for #{primary_container.path}"
|
2018-07-16 20:22:37 +02:00
|
|
|
|
2020-12-21 15:43:25 +01:00
|
|
|
basename = downloader.basename
|
2018-07-23 23:04:49 +02:00
|
|
|
|
2021-02-12 18:33:37 +05:30
|
|
|
if (nested_container = @cask.container&.nested)
|
2018-07-23 23:04:49 +02:00
|
|
|
Dir.mktmpdir do |tmpdir|
|
|
|
|
tmpdir = Pathname(tmpdir)
|
|
|
|
primary_container.extract(to: tmpdir, basename: basename, verbose: verbose?)
|
|
|
|
|
2018-11-02 14:26:35 +01:00
|
|
|
FileUtils.chmod_R "+rw", tmpdir/nested_container, force: true, verbose: verbose?
|
|
|
|
|
2019-04-09 21:45:35 +00:00
|
|
|
UnpackStrategy.detect(tmpdir/nested_container, merge_xattrs: true)
|
2020-12-04 00:07:02 +01:00
|
|
|
.extract_nestedly(to: to, verbose: verbose?)
|
2018-07-23 23:04:49 +02:00
|
|
|
end
|
|
|
|
else
|
2020-12-04 00:07:02 +01:00
|
|
|
primary_container.extract_nestedly(to: to, basename: basename, verbose: verbose?)
|
2018-07-23 23:04:49 +02:00
|
|
|
end
|
2018-08-31 13:16:11 +00:00
|
|
|
|
|
|
|
return unless quarantine?
|
|
|
|
return unless Quarantine.available?
|
|
|
|
|
2020-12-04 00:07:02 +01:00
|
|
|
Quarantine.propagate(from: primary_container.path, to: to)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def install_artifacts
|
2020-07-06 15:41:58 -04:00
|
|
|
artifacts = @cask.artifacts
|
2016-12-04 23:14:35 +01:00
|
|
|
already_installed_artifacts = []
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
odebug "Installing artifacts"
|
2020-07-06 15:41:58 -04:00
|
|
|
odebug "#{artifacts.length} #{"artifact".pluralize(artifacts.length)} defined", artifacts
|
2016-12-04 23:14:35 +01:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
artifacts.each do |artifact|
|
2017-02-05 07:47:54 +01:00
|
|
|
next unless artifact.respond_to?(:install_phase)
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2017-02-05 23:27:35 +01:00
|
|
|
odebug "Installing artifact of class #{artifact.class}"
|
2017-05-19 19:13:23 +02:00
|
|
|
|
2020-09-01 14:05:52 +01:00
|
|
|
next if artifact.is_a?(Artifact::Binary) && !binaries?
|
2017-05-19 19:13:23 +02:00
|
|
|
|
2017-04-06 00:33:31 +02:00
|
|
|
artifact.install_phase(command: @command, verbose: verbose?, force: force?)
|
2017-01-23 14:19:14 +01:00
|
|
|
already_installed_artifacts.unshift(artifact)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2019-02-02 17:11:37 +01:00
|
|
|
|
|
|
|
save_config_file
|
2018-09-02 20:14:54 +01:00
|
|
|
rescue => e
|
2016-12-04 23:14:35 +01:00
|
|
|
begin
|
|
|
|
already_installed_artifacts.each do |artifact|
|
2020-09-01 14:05:52 +01:00
|
|
|
if artifact.respond_to?(:uninstall_phase)
|
|
|
|
odebug "Reverting installation of artifact of class #{artifact.class}"
|
|
|
|
artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?)
|
|
|
|
end
|
2019-02-06 19:04:29 +01:00
|
|
|
|
|
|
|
next unless artifact.respond_to?(:post_uninstall_phase)
|
|
|
|
|
|
|
|
odebug "Reverting installation of artifact of class #{artifact.class}"
|
|
|
|
artifact.post_uninstall_phase(command: @command, verbose: verbose?, force: force?)
|
|
|
|
end
|
2016-12-04 23:14:35 +01:00
|
|
|
ensure
|
|
|
|
purge_versioned_files
|
2016-12-16 18:22:04 +01:00
|
|
|
raise e
|
2016-12-04 23:14:35 +01:00
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-10-18 21:42:43 -04:00
|
|
|
# TODO: move dependencies to a separate class,
|
|
|
|
# dependencies should also apply for `brew cask stage`,
|
|
|
|
# override dependencies with `--force` or perhaps `--force-deps`
|
2016-09-24 13:52:43 +02:00
|
|
|
def satisfy_dependencies
|
|
|
|
return unless @cask.depends_on
|
|
|
|
|
|
|
|
macos_dependencies
|
|
|
|
arch_dependencies
|
|
|
|
x11_dependencies
|
2019-11-01 20:28:24 +01:00
|
|
|
cask_and_formula_dependencies
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def macos_dependencies
|
|
|
|
return unless @cask.depends_on.macos
|
2019-08-15 10:14:10 +02:00
|
|
|
return if @cask.depends_on.macos.satisfied?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2019-08-15 10:14:10 +02:00
|
|
|
raise CaskError, @cask.depends_on.macos.message(type: :cask)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def arch_dependencies
|
|
|
|
return if @cask.depends_on.arch.nil?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
@current_arch ||= { type: Hardware::CPU.type, bits: Hardware::CPU.bits }
|
2016-10-23 14:44:14 +02:00
|
|
|
return if @cask.depends_on.arch.any? do |arch|
|
2016-09-24 13:52:43 +02:00
|
|
|
arch[:type] == @current_arch[:type] &&
|
|
|
|
Array(arch[:bits]).include?(@current_arch[:bits])
|
2016-10-23 14:44:14 +02:00
|
|
|
end
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2018-09-02 16:15:09 +01:00
|
|
|
raise CaskError,
|
2019-04-30 08:44:35 +01:00
|
|
|
"Cask #{@cask} depends on hardware architecture being one of " \
|
|
|
|
"[#{@cask.depends_on.arch.map(&:to_s).join(", ")}], " \
|
2021-01-26 15:21:24 -05:00
|
|
|
"but you are running #{@current_arch}."
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def x11_dependencies
|
|
|
|
return unless @cask.depends_on.x11
|
2020-09-15 13:39:06 +01:00
|
|
|
raise CaskX11DependencyError, @cask.token unless MacOS::XQuartz.installed?
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
def graph_dependencies(cask_or_formula, acc = TopologicalHash.new)
|
|
|
|
return acc if acc.key?(cask_or_formula)
|
2017-06-28 17:53:59 +02:00
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
if cask_or_formula.is_a?(Cask)
|
|
|
|
formula_deps = cask_or_formula.depends_on.formula.map { |f| Formula[f] }
|
2020-09-29 23:46:30 +02:00
|
|
|
cask_deps = cask_or_formula.depends_on.cask.map { |c| CaskLoader.load(c, config: nil) }
|
2019-10-31 20:20:55 +01:00
|
|
|
else
|
|
|
|
formula_deps = cask_or_formula.deps.reject(&:build?).map(&:to_formula)
|
2020-09-29 23:46:30 +02:00
|
|
|
cask_deps = cask_or_formula.requirements.map(&:cask).compact
|
|
|
|
.map { |c| CaskLoader.load(c, config: nil) }
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
acc[cask_or_formula] ||= []
|
|
|
|
acc[cask_or_formula] += formula_deps
|
|
|
|
acc[cask_or_formula] += cask_deps
|
2017-06-28 17:53:59 +02:00
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
formula_deps.each do |f|
|
|
|
|
graph_dependencies(f, acc)
|
2017-06-28 17:53:59 +02:00
|
|
|
end
|
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
cask_deps.each do |c|
|
|
|
|
graph_dependencies(c, acc)
|
2018-07-14 03:25:42 +02:00
|
|
|
end
|
2019-10-31 20:20:55 +01:00
|
|
|
|
|
|
|
acc
|
2018-07-14 03:25:42 +02:00
|
|
|
end
|
|
|
|
|
2019-11-01 20:28:24 +01:00
|
|
|
def collect_cask_and_formula_dependencies
|
|
|
|
return @cask_and_formula_dependencies if @cask_and_formula_dependencies
|
2019-10-31 20:20:55 +01:00
|
|
|
|
|
|
|
graph = graph_dependencies(@cask)
|
2018-07-14 03:25:42 +02:00
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
raise CaskSelfReferencingDependencyError, cask.token if graph[@cask].include?(@cask)
|
2018-07-14 03:25:42 +02:00
|
|
|
|
2019-10-31 20:20:55 +01:00
|
|
|
primary_container.dependencies.each do |dep|
|
|
|
|
graph_dependencies(dep, graph)
|
|
|
|
end
|
2018-07-14 03:25:42 +02:00
|
|
|
|
2019-11-01 20:28:24 +01:00
|
|
|
begin
|
2019-11-02 00:33:08 +01:00
|
|
|
@cask_and_formula_dependencies = graph.tsort - [@cask]
|
2019-10-31 20:20:55 +01:00
|
|
|
rescue TSort::Cyclic
|
|
|
|
strongly_connected_components = graph.strongly_connected_components.sort_by(&:count)
|
|
|
|
cyclic_dependencies = strongly_connected_components.last - [@cask]
|
|
|
|
raise CaskCyclicDependencyError.new(@cask.token, cyclic_dependencies.to_sentence)
|
|
|
|
end
|
2019-11-01 20:28:24 +01:00
|
|
|
end
|
2018-07-14 03:25:42 +02:00
|
|
|
|
2019-11-01 20:28:24 +01:00
|
|
|
def missing_cask_and_formula_dependencies
|
|
|
|
collect_cask_and_formula_dependencies.reject do |cask_or_formula|
|
2020-07-12 17:13:04 -07:00
|
|
|
installed = if cask_or_formula.respond_to?(:any_version_installed?)
|
|
|
|
cask_or_formula.any_version_installed?
|
|
|
|
else
|
|
|
|
cask_or_formula.try(:installed?)
|
|
|
|
end
|
2020-09-01 13:55:24 -07:00
|
|
|
installed && (cask_or_formula.respond_to?(:optlinked?) ? cask_or_formula.optlinked? : true)
|
2019-10-31 20:20:55 +01:00
|
|
|
end
|
2019-11-01 20:28:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def cask_and_formula_dependencies
|
|
|
|
return if installed_as_dependency?
|
|
|
|
|
|
|
|
formulae_and_casks = collect_cask_and_formula_dependencies
|
|
|
|
|
|
|
|
return if formulae_and_casks.empty?
|
|
|
|
|
|
|
|
missing_formulae_and_casks = missing_cask_and_formula_dependencies
|
2019-10-31 20:20:55 +01:00
|
|
|
|
2019-11-01 20:28:24 +01:00
|
|
|
if missing_formulae_and_casks.empty?
|
2020-07-29 17:31:11 -04:00
|
|
|
puts "All formula dependencies satisfied."
|
2019-10-31 20:20:55 +01:00
|
|
|
return
|
2018-07-14 03:25:42 +02:00
|
|
|
end
|
|
|
|
|
2019-11-01 20:28:24 +01:00
|
|
|
ohai "Installing dependencies: #{missing_formulae_and_casks.map(&:to_s).join(", ")}"
|
|
|
|
missing_formulae_and_casks.each do |cask_or_formula|
|
2019-10-31 20:20:55 +01:00
|
|
|
if cask_or_formula.is_a?(Cask)
|
|
|
|
if skip_cask_deps?
|
|
|
|
opoo "`--skip-cask-deps` is set; skipping installation of #{@cask}."
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
Installer.new(
|
|
|
|
cask_or_formula,
|
|
|
|
binaries: binaries?,
|
|
|
|
verbose: verbose?,
|
|
|
|
installed_as_dependency: true,
|
|
|
|
force: false,
|
|
|
|
).install
|
|
|
|
else
|
2020-11-18 05:37:12 +01:00
|
|
|
fi = FormulaInstaller.new(
|
|
|
|
cask_or_formula,
|
|
|
|
**{
|
|
|
|
show_header: true,
|
|
|
|
installed_as_dependency: true,
|
|
|
|
installed_on_request: false,
|
|
|
|
verbose: verbose?,
|
|
|
|
}.compact,
|
|
|
|
)
|
|
|
|
fi.prelude
|
|
|
|
fi.fetch
|
|
|
|
fi.install
|
|
|
|
fi.finish
|
2019-10-31 20:20:55 +01:00
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2019-03-11 21:20:02 -04:00
|
|
|
def caveats
|
|
|
|
self.class.caveats(@cask)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def save_caskfile
|
2017-04-20 10:48:32 +02:00
|
|
|
old_savedir = @cask.metadata_timestamped_path
|
2017-03-11 18:55:16 +01:00
|
|
|
|
|
|
|
return unless @cask.sourcefile_path
|
|
|
|
|
2017-04-20 10:48:32 +02:00
|
|
|
savedir = @cask.metadata_subdir("Casks", timestamp: :now, create: true)
|
2017-03-11 18:55:16 +01:00
|
|
|
FileUtils.copy @cask.sourcefile_path, savedir
|
2017-09-24 19:24:46 +01:00
|
|
|
old_savedir&.rmtree
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2019-02-02 17:11:37 +01:00
|
|
|
def save_config_file
|
2019-02-09 02:19:01 +01:00
|
|
|
@cask.config_path.atomic_write(@cask.config.to_json)
|
2019-02-02 17:11:37 +01:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def uninstall
|
2018-02-09 11:31:51 +09:00
|
|
|
oh1 "Uninstalling Cask #{Formatter.identifier(@cask)}"
|
2017-11-10 10:05:18 -03:00
|
|
|
uninstall_artifacts(clear: true)
|
2021-01-07 13:49:05 -08:00
|
|
|
remove_config_file if !reinstall? && !upgrade?
|
2017-10-29 17:31:07 -03:00
|
|
|
purge_versioned_files
|
|
|
|
purge_caskroom_path if force?
|
|
|
|
end
|
|
|
|
|
2019-02-02 17:11:37 +01:00
|
|
|
def remove_config_file
|
|
|
|
FileUtils.rm_f @cask.config_path
|
|
|
|
@cask.config_path.parent.rmdir_if_possible
|
|
|
|
end
|
|
|
|
|
2017-10-30 23:29:00 -03:00
|
|
|
def start_upgrade
|
|
|
|
uninstall_artifacts
|
2017-11-28 17:37:36 +00:00
|
|
|
backup
|
2017-11-28 13:00:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def backup
|
2017-11-28 17:37:36 +00:00
|
|
|
@cask.staged_path.rename backup_path
|
2017-11-28 21:00:16 +00:00
|
|
|
@cask.metadata_versioned_path.rename backup_metadata_path
|
2017-11-28 13:00:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def restore_backup
|
2021-01-07 13:49:05 -08:00
|
|
|
return if !backup_path.directory? || !backup_metadata_path.directory?
|
2017-11-28 13:00:08 +00:00
|
|
|
|
|
|
|
Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
|
2017-11-28 21:00:16 +00:00
|
|
|
Pathname.new(@cask.metadata_versioned_path).rmtree if @cask.metadata_versioned_path.exist?
|
2017-11-28 13:00:08 +00:00
|
|
|
|
2017-11-28 17:37:36 +00:00
|
|
|
backup_path.rename @cask.staged_path
|
2017-11-28 21:00:16 +00:00
|
|
|
backup_metadata_path.rename @cask.metadata_versioned_path
|
2017-10-30 23:29:00 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
def revert_upgrade
|
|
|
|
opoo "Reverting upgrade for Cask #{@cask}"
|
2017-11-28 17:37:36 +00:00
|
|
|
restore_backup
|
2017-11-06 21:27:02 -03:00
|
|
|
install_artifacts
|
2017-10-30 23:29:00 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize_upgrade
|
2019-10-24 15:15:40 +02:00
|
|
|
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
|
|
|
|
|
2017-11-28 20:36:36 +00:00
|
|
|
purge_backed_up_versioned_files
|
2017-11-11 17:21:13 -03:00
|
|
|
|
|
|
|
puts summary
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-11-10 10:05:18 -03:00
|
|
|
def uninstall_artifacts(clear: false)
|
2017-10-04 17:08:35 +02:00
|
|
|
artifacts = @cask.artifacts
|
2017-02-16 17:10:40 +01:00
|
|
|
|
2020-07-06 15:41:58 -04:00
|
|
|
odebug "Uninstalling artifacts"
|
|
|
|
odebug "#{artifacts.length} #{"artifact".pluralize(artifacts.length)} defined", artifacts
|
2017-02-16 17:10:40 +01:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
artifacts.each do |artifact|
|
2020-09-01 14:05:52 +01:00
|
|
|
if artifact.respond_to?(:uninstall_phase)
|
|
|
|
odebug "Uninstalling artifact of class #{artifact.class}"
|
|
|
|
artifact.uninstall_phase(
|
|
|
|
command: @command, verbose: verbose?, skip: clear, force: force?, upgrade: upgrade?,
|
|
|
|
)
|
|
|
|
end
|
2019-02-06 19:04:29 +01:00
|
|
|
|
|
|
|
next unless artifact.respond_to?(:post_uninstall_phase)
|
|
|
|
|
|
|
|
odebug "Post-uninstalling artifact of class #{artifact.class}"
|
|
|
|
artifact.post_uninstall_phase(
|
|
|
|
command: @command, verbose: verbose?, skip: clear, force: force?, upgrade: upgrade?,
|
|
|
|
)
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def zap
|
2021-01-24 21:40:41 -05:00
|
|
|
ohai "Implied `brew uninstall --cask #{@cask}`"
|
2016-09-24 13:52:43 +02:00
|
|
|
uninstall_artifacts
|
2017-10-04 17:08:35 +02:00
|
|
|
if (zap_stanzas = @cask.artifacts.select { |a| a.is_a?(Artifact::Zap) }).empty?
|
2016-09-24 13:52:43 +02:00
|
|
|
opoo "No zap stanza present for Cask '#{@cask}'"
|
2017-04-06 00:33:31 +02:00
|
|
|
else
|
|
|
|
ohai "Dispatching zap stanza"
|
|
|
|
zap_stanzas.each do |stanza|
|
|
|
|
stanza.zap_phase(command: @command, verbose: verbose?, force: force?)
|
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
ohai "Removing all staged versions of Cask '#{@cask}'"
|
|
|
|
purge_caskroom_path
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-11-28 17:37:36 +00:00
|
|
|
def backup_path
|
2018-09-02 20:14:54 +01:00
|
|
|
return if @cask.staged_path.nil?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2018-04-29 05:34:32 +02:00
|
|
|
Pathname("#{@cask.staged_path}.upgrading")
|
2017-11-28 13:00:08 +00:00
|
|
|
end
|
|
|
|
|
2017-11-28 21:00:16 +00:00
|
|
|
def backup_metadata_path
|
2018-09-02 20:14:54 +01:00
|
|
|
return if @cask.metadata_versioned_path.nil?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2018-04-29 05:34:32 +02:00
|
|
|
Pathname("#{@cask.metadata_versioned_path}.upgrading")
|
2017-11-28 21:00:16 +00:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def gain_permissions_remove(path)
|
|
|
|
Utils.gain_permissions_remove(path, command: @command)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-11-28 20:36:36 +00:00
|
|
|
def purge_backed_up_versioned_files
|
2016-09-24 13:52:43 +02:00
|
|
|
# versioned staged distribution
|
2018-04-29 05:34:32 +02:00
|
|
|
gain_permissions_remove(backup_path) if backup_path&.exist?
|
2017-11-28 13:00:08 +00:00
|
|
|
|
2018-09-03 20:12:29 +01:00
|
|
|
# Homebrew Cask metadata
|
2018-04-29 05:34:32 +02:00
|
|
|
return unless backup_metadata_path.directory?
|
|
|
|
|
|
|
|
backup_metadata_path.children.each do |subdir|
|
|
|
|
gain_permissions_remove(subdir)
|
2017-11-28 21:00:16 +00:00
|
|
|
end
|
|
|
|
backup_metadata_path.rmdir_if_possible
|
2017-11-28 18:03:57 +00:00
|
|
|
end
|
|
|
|
|
2017-11-10 10:05:18 -03:00
|
|
|
def purge_versioned_files
|
|
|
|
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
# versioned staged distribution
|
2018-04-29 05:34:32 +02:00
|
|
|
gain_permissions_remove(@cask.staged_path) if @cask.staged_path&.exist?
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-03 20:12:29 +01:00
|
|
|
# Homebrew Cask metadata
|
2018-04-29 05:34:32 +02:00
|
|
|
if @cask.metadata_versioned_path.directory?
|
2017-04-20 10:48:32 +02:00
|
|
|
@cask.metadata_versioned_path.children.each do |subdir|
|
2018-04-29 05:34:32 +02:00
|
|
|
gain_permissions_remove(subdir)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
2018-04-29 05:34:32 +02:00
|
|
|
|
|
|
|
@cask.metadata_versioned_path.rmdir_if_possible
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
2017-11-07 22:27:04 -03:00
|
|
|
@cask.metadata_master_container_path.rmdir_if_possible unless upgrade?
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
# toplevel staged distribution
|
2017-11-07 22:27:04 -03:00
|
|
|
@cask.caskroom_path.rmdir_if_possible unless upgrade?
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def purge_caskroom_path
|
|
|
|
odebug "Purging all staged versions of Cask #{@cask}"
|
|
|
|
gain_permissions_remove(@cask.caskroom_path)
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|