Skip to content

Instantly share code, notes, and snippets.

@jklausa
Last active April 20, 2022 14:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jklausa/5780d5126d97f73b70a91aeab58f7f4a to your computer and use it in GitHub Desktop.
Save jklausa/5780d5126d97f73b70a91aeab58f7f4a to your computer and use it in GitHub Desktop.
curl Xcode
#!/bin/bash
# Useful for downloading Xcode on machines where you don't want to log-in with your Apple ID (e.g. CI
# machines, or other low-trust environemnts).
# Requires you to manually log-in to the Apple Dev Portal, and extract contents of the ADCDownloadAuth cookie
# (easiest way to do it is using Web Inspector, going to the "Storage" Pane, selecting "Cookies" in the left sidebar,
# and copying the appropriate value.
#
# Usage:
# curl https://gist.githubusercontent.com/jklausa/5780d5126d97f73b70a91aeab58f7f4a/raw/ | bash -s -- XCODE-URL COOKIE_VALUE
# e.g.
# curl https://gist.githubusercontent.com/jklausa/5780d5126d97f73b70a91aeab58f7f4a/raw/ | bash -s -- https://download.developer.apple.com/Developer_Tools/Xcode_12.5.1/Xcode_12.5.1.xip ThIsIsNotARealCoOkiEJusTanExample
#
# Based on https://gist.github.com/iandundas/fabe07455e5216442a421922361f698c#gistcomment-3721309,
# rewritten to use just plain curl; so it's runnable on vanilla macOS installs.
set -e
set -u
exec curl \
--cookie ADCDownloadAuth=$2 \
--remote-name \
"$1"
@jklausa
Copy link
Author

jklausa commented Aug 23, 2021

With credits to @bawr for pushing me to prettify and simplify this.

@timsutton
Copy link

While I can fetch some other trivial items like HTTP Streaming Tools with only ADCDownloadAuth, for at least Xcode it seems like I also need the myacinfo cookie value.

@jklausa
Copy link
Author

jklausa commented Apr 20, 2022

Hmm, interesting, that definitely wasn’t the case a while ago!

I’ll try to see if I can replicate this and maybe update the gist.

@jklausa
Copy link
Author

jklausa commented Apr 20, 2022

@timsutton Hmm, I can't replicate this on my end, at least for Xcode 13.3.1, just doing

curl https://gist.githubusercontent.com/jklausa/5780d5126d97f73b70a91aeab58f7f4a/raw/ | bash -s -- https://download.developer.apple.com/Developer_Tools/Xcode_13.3.1/Xcode_13.3.1.xip <<My ADCDownloadAuth Cookie Goes here>>

does download it...

Are you trying to get a different/older version?

@timsutton
Copy link

I was trying Xcode 13.3.1, but I just figured out why I was needing the extra cookie value:

I was copy/pasting in the URL I got from the rendered HTML links off of xcodereleases.com, like: https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_13.3.1/Xcode_13.3.1.xip. It looks like these URLs do need the myacinfo cookie, but the simpler URLs like the one from this script's comments work with just ADCDownloadAuth like you just confirmed.

When I looked again at my Chrome network log from downloading Xcode from ADC, it does indeed use the shorter URL, and so does the data JSON from xcodereleases. Maybe those other URLs at /services-account/download are there to help redirect the user through the sign-in flow?

Anyway, mystery solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment