Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Download all Apple open source OS X files at once UNIX
While it is well known that Mac OS X contains open source code, how to access and download that source code is perhaps less well known. Apple publishes all its open source code on their Apple Open Source site. However, this site makes you download each program individually, without an obvious option to download an entire OS X release at once (i.e., all public sources for 10.6.1).

So I wrote the following bash script to automate the download procedure. It downloads the individual tarballs for each program, expands them locally, and then rolls everything up into one big tarball for local storage. Some caveats are that this script does not build the code, and that you are bound by a variety of licenses which are not included here (because no Apple code is included here).
#!/usr/bin/env bash
# --- applesource.bash --- downloads source code for an entire Apple release

# Take input from command-line (use "10.5.8", "10.6.1", etc.)
  version="mac-os-x-`echo $* | tr -d "."`"

# URL:
  homepage="http://www.opensource.apple.com"
  URL="${homepage}/release/${version}/"

# Announce beginning, and prepare a directory for the untarred sources
  echo "Preparing to download..."
  sources="./${version}-sources"
  mkdir -p ${sources}
  
# Process the webpage for the locations of the tarballs themselves
  curl --silent ${URL} | sed -n 's/<a href="\(.*.tar.gz\)">/\1/p' | \
    while read line; do
    
      # Find and announce the name of the next tarball to be downloaded
        tarball=".${line}"
        echo -e "\nDownloading `basename ${tarball}`..."

      # Download the tarball and keep Apple's original directory structure intact
        curl --create-dirs --output ${tarball} "${homepage}${line}"

      # Untar into the "sources" directory (see line 13)
        tar xfz "${tarball}" -C ${sources}

    done

# Compress all sourcefiles into a single tarball for posterity
  echo "Creating ${version}.tar.gz from all sources..."
  tar cfvz "${version}.tar.gz" ${sources}

# Explicitly show that everything finished.
  echo "Done."

# I like for my Mac to talk to me, although sometimes this can be creepy.
  say "The source of ${version} is now ready."
Save the above somewhere on your path, make it executable (chmod a+x scriptname), and then run it with the version number you'd like to download: getsource 10.6.1, for instance. I am a bit shy about releasing my scripts, so please be gentle!

[robg adds: I tested this and it worked as described.]
    •    
  • Currently 4.20 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[2,813 views]  

Download all Apple open source OS X files at once | 2 comments | Create New Account
Click here to return to the 'Download all Apple open source OS X files at once' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Download all Apple open source OS X files at once
Authored by: JwithiMacG5 on Thu, Oct 29 2009 at 10:01AM PDT
You can also download the sources using Apple's DarwinBuild tool: http://darwinbuild.macosforge.org/

[ Reply to This | # ]
Download all Apple open source OS X files at once
Authored by: ehunt123 on Mon, Nov 2 2009 at 6:17AM PST
A talented OSX developer (person behind some of the AppleTV stuff it seems) has also posted the source to some automator actions/services to accomplish the same. I personally use the method mentioned via the first person, since you can build right from MacPorts, but it is a nice alternative:

http://github.com/AlanQuatermain/DownloadDarwinSource/

You need his UnTar action--which is rather handy in other settings—in order for it to work.





[ Reply to This | # ]