Download Xcode from command line

Hi everyone, I am trying to download Xcode from command line the following way:

wget --certificate=certificate.pem --private-key=private-key.pem --server-response https://download.developer.apple.com/Developer_Tools/Xcode_13.3.1/Xcode_13.3.1.xip%C2%A0--no-check-certificate --load-cookies=cookies.txt

I am getting the following error: HTTP request sent, awaiting response... 302 Moved Temporarily Location: https://developer.apple.com/unauthorized/

I have the certificate and private key from developer.apple.com and I am using them for authentication(correct me if I am wrong and they cannot be used for authentication).

From several forums I found that the error regarding authorization could also be from cookies, so I got the cookies. Still the same error.

I need the download of Xcode to be done from command line so that I can then automate the procedure using ansible playbooks (basically for the purpose of downloading and installing it on multiple mac machines.) Please, if the approach is entirely wrong, provide me with the right guide how to download Xcode from developer.apple.com site.

I’ve done this in the past:

No certificates.

Visit the site in Safari. Log in. Open the developer console. Extract the cookies. Pass the cookies to wget (maybe using —header).

(I seem to recall doing something like modifying the URL to deliberately get an error page???)

Of course that relies on cookies that will expire quite soon. It may not work for your situation.

(what certificate exactly are you referring to?)

Thank you so much for your response endecotp. I tried without certificates but got the same error. Here is how I tried but used cookies from google chrome instead of safari. Is there difference?

wget https://download.developer.apple.com/Developer_Tools/Xcode_13.3.1/Xcode_13.3.1.xip --load-cookies=cookies.txt

I created signing certificates that should have worked for logging to developer.apple.com - https://developer.apple.com/support/certificates

Here are the notes I wrote when I did this:

XCode downloads are available from https://developer.apple.com/download/all/?q=xcode

Example link: https://download.developer.apple.com/Developer_Tools/Xcode_13.1/Xcode_13.1.xip

But these require dev programme membership; wgetting without cookies returns an HTML page.

To get the required cookies, in Safari visit a truncated URL: https://download.developer.apple.com/Developer_Tools/

Do this with the Javascript console open. Select the network tab and copy the entire Cookie header 
(not the individual cookies).

Now it's possible to wget on (a linux system):

wget --header 'Cookie: s_fid=2B4119F75B4D610EB0-03724F1FC4C7A124C7; s_sq=awdappledeveloper%3D%2526pid%253Dall%252520-%252520downloads%252520-%252520apple%252520developer%2526pidt%253D1%2526oid%253Dhttps%25253A%25252F%25252Fdownload.developer.apple.com%25252FDeveloper_Tools%25252FXcode_13.1%25252FXcode_13.1.xip%2526ot%253DA; ADCDownloadAuth=knTCDvQAPHK4KPOjAT94Pc3FpNJ85Ual37QZ79Or6tXX1AZKPydEwLyL%2BwibpoYivJyPZiG%0D%0AaaKVS6pMXAB6qCTU20pKZpC%2BdgN9oskJIqh6TwJQYh0JAdx0%2BLIcqJjazfQQLVgPsi3ZGMb4Qikx%0D%0ARt%2FRr%2BnkEWbg%2FWCnPccflERO%0D%0A; DSESSIONID=6oao4455uh1la64npvbhnvshguipxgpv5m26g5nhovsmbcvm5ktmr12886; s_cc=true; s_pathLength=developer%3D2%2C; s_vi=[CS]v1|30F814585C0EB6E9FE-60000DF2B4C69343[CE]; itctx=eyJjcCI2A6MTUyMDU2LCJkcyI6ODI1LCJleCI6IjIwMjItMS0yOCAyMzozMjo0OSJ9|h6mjs3ie3lfiatgfe9ju2p2nkl|QNyPC5-zW1WDpQB8p7OSDhVplzA; itcdq=0; dc=st; acn01=GKj9P3KmQzUEwBru4SafYOR/I3Z22WS3IUAxpjB8AA9GygCj7Mo=; dslang=GB-EN; myacinfo=DAWTKNV323952cf8084a204fb20ab2508441a07d02d3b0b3f87efe6467be6061c76dfb675cac18c6e8d66d2ced0a45e7110e0b2d8f0c692772721e9dc355651ba37ee1496b21f889db5d66ec067597b0370108ee15de612fca13478683a2c4969e6b35a0b88f6cc3e61ac5e36ec44b910f11acaa309cd782c9bfb4877ade43b593b5f1b77af04db72dcfae906039d53b721ca18cddd027b210302099728c496af56e21797bf9dab1a2b7670f27e0fa0fa7d905ae7a515ba336ab66a14122edfcceab6e46a11efdbdafa7030cdaeb0738a377ea6717bd50bf654a9e83dc0a07ba859f5fbb10493f3a1ddae183d4ab613e52b5397c30d2a42242ccb991f683ec2b853d587499a7f55aa5097acd25ee50521b0b5a138d854c2caffc31efd70a7a51e2a03d17020e2e29071a006222209ab63e9f65ff9b1fd5ee575e732ffebd2ef347506724e00ba63923585a47V3; site=GBR; geo=GB; atsvric=7MyA/S3ETe4iziHyMQFk9Vz6JdDSemvWEiVe5WftPh3szwKnokSI/B2doLHy642KJkzxnQsthS5rMHFYm2XjFB+GyF6pf4fhfijroaqCIlOkv5lbijSpgShDnIHXw76UgcADLxhfzgwtQ==; dssf=1; dssid2=d8e8d12-g6e-ab7b-9ebdac157a75' \
     'https://download.developer.apple.com/Developer_Tools/Xcode_13.1/Xcode_13.1.xip'

(I have slightly munged the strings just in case they contain something I'm supposed to keep secret!)

I think I may have tried using a cookies.txt file but gave up used --header 'Cookie: ...' instead. I forget.

I created signing certificates that should have worked for logging to developer.apple.com - https://developer.apple.com/support/certificates

Why do you believe that those certificates will work for logging on to developer.apple.com? Maybe they do, but I don't see any mention of that on the web page you linked to.

Thank you so much for your response endecotp. I think you are absolutely right about certificates and they cannot be used for authentication. I tried the way you told me but several headers like acn01, atsvric and dssid2 were missing from my cookies in browser. Eventually, I got the same error. I guess the way I am trying to automate the installation process is wrong and I need to download the required version of Xcode, have it saved on ftp server and then make all my machines to it and download. The downside of this approach is that Xcode itself is very heavy(about 9GB) so it will require several hours to download from another server to the target machines, which may not be the best way.

Download Xcode from command line
 
 
Q