2011-08-23 23:30:52 +01:00
|
|
|
require 'cmd/install'
|
|
|
|
|
|
|
|
class Fixnum
|
|
|
|
def plural_s
|
|
|
|
if self > 1 then "s" else "" end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def upgrade
|
2012-03-07 12:50:15 +00:00
|
|
|
if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero?
|
|
|
|
# note we only abort if Homebrew is *not* installed as sudo and the user
|
|
|
|
# calls brew as root. The fix is to chown brew to root.
|
|
|
|
abort "Cowardly refusing to `sudo brew upgrade'"
|
|
|
|
end
|
|
|
|
|
2011-08-23 23:30:52 +01:00
|
|
|
Homebrew.perform_preinstall_checks
|
|
|
|
|
2013-01-19 19:45:18 -05:00
|
|
|
if ARGV.named.empty?
|
2012-07-10 22:09:31 -05:00
|
|
|
require 'cmd/outdated'
|
2013-03-11 16:41:08 +01:00
|
|
|
upgrade_pinned = false
|
2013-01-19 19:45:18 -05:00
|
|
|
outdated = Homebrew.outdated_brews
|
2011-08-23 23:30:52 +01:00
|
|
|
else
|
2013-03-11 16:41:08 +01:00
|
|
|
upgrade_pinned = true
|
2013-01-19 19:45:18 -05:00
|
|
|
outdated = ARGV.formulae.select do |f|
|
2012-08-18 18:37:32 -05:00
|
|
|
if f.installed?
|
|
|
|
onoe "#{f}-#{f.installed_version} already installed"
|
|
|
|
elsif not f.rack.exist? or f.rack.children.empty?
|
2012-03-07 11:17:36 +00:00
|
|
|
onoe "#{f} not installed"
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
2011-09-02 09:55:37 +01:00
|
|
|
end
|
2013-01-19 19:45:18 -05:00
|
|
|
exit 1 if outdated.empty?
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
|
2013-03-11 16:41:08 +01:00
|
|
|
unless upgrade_pinned
|
|
|
|
pinned = outdated.select { |f| f.pinned? }
|
|
|
|
outdated -= pinned
|
|
|
|
end
|
|
|
|
|
|
|
|
if outdated.length > 0
|
2011-08-25 18:02:36 -07:00
|
|
|
oh1 "Upgrading #{outdated.length} outdated package#{outdated.length.plural_s}, with result:"
|
2011-09-11 13:06:05 -07:00
|
|
|
puts outdated.map{ |f| "#{f.name} #{f.version}" } * ", "
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
2013-03-11 16:41:08 +01:00
|
|
|
if not upgrade_pinned and pinned.length > 0
|
|
|
|
oh1 "Not upgrading #{pinned.length} pinned package#{outdated.length.plural_s}:"
|
|
|
|
puts pinned.map{ |f| "#{f.name} #{f.version}" } * ", "
|
|
|
|
end
|
2011-08-23 23:30:52 +01:00
|
|
|
|
2011-09-11 13:06:05 -07:00
|
|
|
outdated.each do |f|
|
2012-03-07 11:17:36 +00:00
|
|
|
upgrade_formula f
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
end
|
2012-03-07 11:17:36 +00:00
|
|
|
|
|
|
|
def upgrade_formula f
|
2013-01-23 00:26:31 -06:00
|
|
|
tab = Tab.for_formula(f)
|
2012-03-07 11:17:36 +00:00
|
|
|
outdated_keg = Keg.new(f.linked_keg.realpath) rescue nil
|
|
|
|
|
2013-01-23 00:26:27 -06:00
|
|
|
installer = FormulaInstaller.new(f)
|
|
|
|
installer.tab = tab
|
2012-03-07 11:17:36 +00:00
|
|
|
installer.show_header = false
|
|
|
|
|
|
|
|
oh1 "Upgrading #{f.name}"
|
|
|
|
|
|
|
|
# first we unlink the currently active keg for this formula otherwise it is
|
|
|
|
# possible for the existing build to interfere with the build we are about to
|
|
|
|
# do! Seriously, it happens!
|
|
|
|
outdated_keg.unlink if outdated_keg
|
|
|
|
|
|
|
|
installer.install
|
|
|
|
installer.caveats
|
2012-03-07 13:48:04 +00:00
|
|
|
installer.finish
|
2013-03-11 16:41:08 +01:00
|
|
|
|
|
|
|
# If the formula was pinned, and we were force-upgrading it, unpin and
|
|
|
|
# pin it again to get a symlink pointing to the correct keg.
|
|
|
|
if f.pinned?
|
|
|
|
f.unpin
|
|
|
|
f.pin
|
|
|
|
end
|
2013-01-08 19:54:32 -06:00
|
|
|
rescue FormulaInstallationAlreadyAttemptedError
|
|
|
|
# We already attempted to upgrade f as part of the dependency tree of
|
|
|
|
# another formula. In that case, don't generate an error, just move on.
|
2012-03-07 11:17:36 +00:00
|
|
|
rescue CannotInstallFormulaError => e
|
2012-04-30 14:08:59 +10:00
|
|
|
ofail e
|
2012-03-07 11:17:36 +00:00
|
|
|
rescue BuildError => e
|
|
|
|
e.dump
|
|
|
|
puts
|
2012-03-15 10:57:34 +13:00
|
|
|
Homebrew.failed = true
|
2012-03-07 11:17:36 +00:00
|
|
|
ensure
|
|
|
|
# restore previous installation state if build failed
|
2012-03-07 13:48:04 +00:00
|
|
|
outdated_keg.link if outdated_keg and not f.installed? rescue nil
|
2012-03-07 11:17:36 +00:00
|
|
|
end
|
|
|
|
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|