lib/xcode/install.rb in xcode-install-0.9.0 vs lib/xcode/install.rb in xcode-install-0.9.1
- old
+ new
@@ -7,19 +7,20 @@
module XcodeInstall
class Curl
COOKIES_PATH = Pathname.new('/tmp/curl-cookies.txt')
- def fetch(url, directory = nil, cookies = nil, output = nil)
+ def fetch(url, directory = nil, cookies = nil, output = nil, progress = true)
options = cookies.nil? ? '' : "-b '#{cookies}' -c #{COOKIES_PATH}"
# options += ' -vvv'
uri = URI.parse(url)
output ||= File.basename(uri.path)
output = (Pathname.new(directory) + Pathname.new(output)) if directory
- command = "curl #{options} -L -C - -# -o #{output} #{url}"
+ progress = progress ? '-#' : '-s'
+ command = "curl #{options} -L -C - #{progress} -o #{output} #{url}"
IO.popen(command).each do |fd|
puts(fd)
end
result = $CHILD_STATUS.to_i == 0
@@ -41,16 +42,16 @@
def current_symlink
File.symlink?(SYMLINK_PATH) ? SYMLINK_PATH : nil
end
- def download(version)
+ def download(version, progress)
return unless exist?(version)
xcode = seedlist.find { |x| x.name == version }
dmg_file = Pathname.new(File.basename(xcode.path))
- result = Curl.new.fetch(xcode.url, CACHE_DIR, spaceship.cookie, dmg_file)
+ result = Curl.new.fetch(xcode.url, CACHE_DIR, spaceship.cookie, dmg_file, progress)
result ? CACHE_DIR + dmg_file : nil
end
def exist?(version)
list_versions.include?(version)
@@ -102,13 +103,13 @@
end
FileUtils.rm_f(dmgPath) if clean
end
- def install_version(version, switch = true, clean = true, install = true)
+ def install_version(version, switch = true, clean = true, install = true, progress = true)
return if version.nil?
- dmg_path = get_dmg(version)
+ dmg_path = get_dmg(version, progress)
fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil?
install_dmg(dmg_path, "-#{version.split(' ')[0]}", switch, clean) if install
end
@@ -141,10 +142,13 @@
def spaceship
@spaceship ||= begin
begin
Spaceship.login(ENV["XCODE_INSTALL_USER"], ENV["XCODE_INSTALL_PASSWORD"])
rescue Spaceship::Client::InvalidUserCredentialsError
+ $stderr.puts 'The specified Apple developer account credentials are incorrect.'
+ exit(1)
+ rescue Spaceship::Client::NoUserCredentialsError
$stderr.puts <<-HELP
Please provide your Apple developer account credentials via the
XCODE_INSTALL_USER and XCODE_INSTALL_PASSWORD environment variables.
HELP
exit(1)
@@ -165,16 +169,16 @@
def enable_developer_mode
`sudo /usr/sbin/DevToolsSecurity -enable`
`sudo /usr/sbin/dseditgroup -o edit -t group -a staff _developer`
end
- def get_dmg(version)
+ def get_dmg(version, progress = true)
if ENV.key?('XCODE_INSTALL_CACHE_DIR')
cache_path = Pathname.new(ENV['XCODE_INSTALL_CACHE_DIR']) + Pathname.new("xcode-#{version}.dmg")
return cache_path if cache_path.exist?
end
- download(version)
+ download(version, progress)
end
def fetch_seedlist
@xcodes = parse_seedlist(spaceship.send(:request, :get, '/services-account/QH65B2/downloadws/listDownloads.action', {
start: "0",