Last active
October 4, 2023 06:32
-
-
Save bazad/871f37736b6e3409e8ab8ed1b8486d28 to your computer and use it in GitHub Desktop.
A script to create a git repository for Apple's XNU kernel source.
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
#! /bin/bash | |
# | |
# git-xnu.sh | |
# Brandon Azad | |
# | |
# A script to download Apple's XNU kernel source code and create a git | |
# repository. | |
# | |
XNU_DIR="xnu" | |
XNU_BASE_URL="https://opensource.apple.com/tarballs/xnu" | |
XNU_ARCHIVE_EXT=".tar.gz" | |
# macOS version, Release date, XNU version | |
XNU_RELEASE_INFO=( | |
10.10.5 "Aug 13, 2015" xnu-2782.40.9 | |
10.11 "Sep 30, 2015" xnu-3247.1.106 | |
10.11.1 "Oct 21, 2015" xnu-3247.10.11 | |
10.11.2 "Dec 08, 2015" xnu-3248.20.55 | |
10.11.3 "Jan 19, 2016" xnu-3248.30.4 | |
10.11.4 "Mar 21, 2016" xnu-3248.40.184 | |
10.11.5 "May 16, 2016" xnu-3248.50.21 | |
10.11.6 "Jul 18, 2016" xnu-3248.60.10 | |
10.12 "Sep 20, 2016" xnu-3789.1.32 | |
10.12.1 "Oct 24, 2016" xnu-3789.21.4 | |
10.12.2 "Dec 13, 2016" xnu-3789.31.2 | |
10.12.3 "Jan 23, 2017" xnu-3789.41.3 | |
10.12.4 "Mar 27, 2017" xnu-3789.51.2 | |
10.12.5 "May 15, 2017" xnu-3789.60.24 | |
10.12.6 "Jul 19, 2017" xnu-3789.70.16 | |
10.13 "Sep 25, 2017" xnu-4570.1.46 | |
10.13.1 "Oct 31, 2017" xnu-4570.20.62 | |
10.13.2 "Dec 06, 2017" xnu-4570.31.3 | |
10.13.3 "Jan 23, 2018" xnu-4570.41.2 | |
10.13.4 "Mar 29, 2018" xnu-4570.51.1 | |
10.13.5 "Jun 01, 2018" xnu-4570.61.1 | |
10.13.6 "Jul 09, 2018" xnu-4570.71.2 | |
#10.14 "Sep 24, 2018" xnu-4903.201.2 | |
10.14.1 "Oct 30, 2018" xnu-4903.221.2 | |
10.14.2 "Dec 05, 2018" xnu-4903.231.4 | |
10.14.3 "Jan 22, 2019" xnu-4903.241.1 | |
#10.14.4 "Mar 25, 2019" xnu-4903.251.3 | |
#10.14.5 "Jul 22, 2019" xnu-4903.261.4 | |
10.15 "Oct 07, 2019" xnu-6153.11.26 | |
) | |
# The number of releases in XNU_RELEASE_INFO. | |
XNU_N_RELEASES="${#XNU_RELEASE_INFO[@]}" | |
XNU_N_RELEASES=$((XNU_N_RELEASES/3)) | |
# Create an XNU download URL from an XNU version. | |
xnu_download_url() { | |
echo "${XNU_BASE_URL}/${1}${XNU_ARCHIVE_EXT}" | |
} | |
# Remove superfluous files that shouldn't be included in the repository. | |
remove_unneeded_files() { | |
find . \( -name '.DS_Store' -o -name '*.auto.html' \) -delete -print || : | |
} | |
# The git author and committer. | |
export GIT_AUTHOR_NAME="Apple Open Source" | |
export GIT_AUTHOR_EMAIL="[email protected]" | |
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" | |
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL" | |
set -e | |
mkdir -p "${XNU_DIR}" | |
cd "${XNU_DIR}" | |
if [ -d .git ]; then | |
git checkout master | |
SKIPTO_XNUVERS=$(git tag --points-at HEAD | grep 'xnu-') | |
else | |
git init | |
SKIPTO_XNUVERS= | |
fi | |
NEWL=$'\n' | |
for ((i=0;i<XNU_N_RELEASES;i++)); do | |
OSVERS="${XNU_RELEASE_INFO[$((3*i))]}" | |
DATE="${XNU_RELEASE_INFO[$((3*i+1))]}" | |
XNUVERS="${XNU_RELEASE_INFO[$((3*i+2))]}" | |
# If we're updating an existing repo, skip to the current version. | |
if [ -n "$SKIPTO_XNUVERS" ]; then | |
if [ "$SKIPTO_XNUVERS" == "$XNUVERS" ]; then | |
SKIPTO_XNUVERS= | |
fi | |
continue | |
fi | |
FMTDATE="$(date -jRf '%b %d, %Y, %H:%M:%S' "${DATE}, 00:00:00")" | |
URL="$(xnu_download_url "${XNUVERS}")" | |
printf "%-20s%-12s%-16s%s\n" "${XNUVERS}" "${OSVERS}" "${DATE}" "${URL}" | |
# Download and add the new files. | |
git rm -rf '*' >/dev/null 2>&1 || : | |
curl -sS "${URL}" | tar -xf- --strip-components=1 | |
remove_unneeded_files | |
git add '*' >/dev/null | |
# Commit the new files. | |
export GIT_COMMITTER_DATE="${FMTDATE}" | |
export GIT_AUTHOR_DATE="${GIT_COMMITTER_DATE}" | |
git commit -m "${XNUVERS}${NEWL}${NEWL}${URL}" -q | |
git tag "${OSVERS}" | |
git tag "${XNUVERS}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment