Last active
April 27, 2017 19:16
-
-
Save ranvel/b7709d5d867899f424837503a2801fa1 to your computer and use it in GitHub Desktop.
Get all Apple macOS sources in one go.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Updated to work in 2017 from the original: http://hints.macworld.com/article.php?story=20091014194517371 | |
| # --- applesource.bash --- downloads source code for an entire Apple release | |
| # Take input from command-line (use "10.5.8", "10.6.1", etc.) | |
| # Example: ./get-sources.sh 10.12.4 | |
| version="macos-`echo $* | tr -d "."`" | |
| # URL: | |
| homepage="https://opensource.apple.com" | |
| URL="${homepage}/release/${version}.html" | |
| # 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..." | |
| # Having the "v" option slows things down considerably | |
| # tar cfvz "${version}.tar.gz" ${sources} | |
| tar cfz "${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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment