Created
March 10, 2011 03:05
-
-
Save derencius/863511 to your computer and use it in GitHub Desktop.
Download Xcode using wget. Useful for slow or intermittent connections. it uses wget and mechanize.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mechanize' | |
if ARGV.size < 3 | |
puts %q{Usage: ruby xcode.rb USERNAME PASSWORD "DOWNLOAD_URL" [WGET_PARAMS]} | |
puts %q{Example: ruby xcode.rb [email protected] 123456 "https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/xcode_4_and_ios_sdk_4.3__final/xcode_4_and_ios_sdk_4.3__final.dmg" } | |
exit | |
end | |
a = Mechanize.new { |agent| | |
agent.user_agent_alias = 'Mac Safari' | |
} | |
a.get('https://developer.apple.com/') do |page| | |
member_page = a.click(page.link_with(:text => /Member Center/)) | |
login = member_page.form_with(:name => 'appleConnectForm') do |form| | |
form.theAccountName = ARGV[0] | |
form.theAccountPW = ARGV[1] | |
end.submit | |
a.redirect_ok = false | |
download_page = a.get(ARGV[2]) | |
system %Q{ wget #{download_page.response["location"]} --header="Cookie: #{download_page.response["set-cookie"]}" #{ARGV[3]}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting this error while running this script
xcode.rb:17:in
'block (2 levels) in <main>': undefined method
theAccountName=' for nil:NilClass (NoMethodError)from (eval):23:in
form_with' from xcode.rb:16:in
block infrom /var/lib/gems/2.1.0/gems/mechanize-2.7.3/lib/mechanize.rb:442:in
get' from xcode.rb:14:in
'