Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created January 28, 2016 20:08
Show Gist options
  • Save meeuw/fb0e63c4763b3cec4ee5 to your computer and use it in GitHub Desktop.
Save meeuw/fb0e63c4763b3cec4ee5 to your computer and use it in GitHub Desktop.
Generate ISO for El Capitan from App Store without any 3rd party tools, I've tested it on Yosemite, most of the credits go to Gabriel L. Somlo
#!/usr/bin/python
import subprocess
import sys
import struct
def pbzx():
if sys.stdin.read(4) != "pbzx":
print "Not a pbzx stream"
sys.exit(1)
flags = struct.unpack(">Q", sys.stdin.read(8))[0]
while (flags & 1 << 24):
flags, length = struct.unpack(">QQ", sys.stdin.read(16))
xz = None
while length:
xbuf = sys.stdin.read(min(4*1024, length))
if xz == None:
xz = xbuf[:8] == "\xfd7zXZ\x00\x00\x00"
if xz:
p = subprocess.Popen("zcat", stdin=subprocess.PIPE)
length -= len(xbuf)
if xz:
p.stdin.write(xbuf)
else:
sys.stdout.write(xbuf)
if xz:
p.stdin.close()
p.wait()
# This is required because Popen seems to flush stdout
sys.stdout.flush()
def main():
subprocess.check_call('''
NAME="El Capitan"
# Mount the installer image:
hdiutil attach "/Applications/Install OS X $NAME.app/Contents/SharedSupport/InstallESD.dmg" -noverify -nobrowse -mountpoint /Volumes/install_app
# Convert the boot image to a sparse bundle:
hdiutil convert /Volumes/install_app/BaseSystem.dmg -format UDSP -o "/tmp/$NAME"
# Increase the sparse bundle capacity for packages, kernel, etc.:
hdiutil resize -size 8g "/tmp/$NAME.sparseimage"
# Mount the sparse bundle target for further processing:
hdiutil attach "/tmp/$NAME.sparseimage" -noverify -nobrowse -mountpoint /Volumes/install_build
# Remove Package link and replace with actual files:
rm /Volumes/install_build/System/Installation/Packages
cp -rp /Volumes/install_app/Packages /Volumes/install_build/System/Installation/
# NEW: As of Yosemite, there are additional installer dependencies:
cp -rp /Volumes/install_app/BaseSystem* /Volumes/install_build/
# NEW: As of Yosemite, we also need a kernel image!
tar -Oxf /Volumes/install_app/Packages/Essentials.pkg Payload|python generateiso.py pbzx|tar -xC/Volumes/install_build/ ./System/Library/Kernels
# Unmount both the installer image and the target sparse bundle:
hdiutil detach /Volumes/install_app
hdiutil detach /Volumes/install_build
# Resize the partition in the sparse bundle to remove any free space:
hdiutil resize -size $(hdiutil resize -limits "/tmp/$NAME.sparseimage" | tail -n 1 | awk '{ print $1 }')b "/tmp/$NAME.sparseimage"
# Convert the sparse bundle to ISO/CD master:
hdiutil convert "/tmp/$NAME.sparseimage" -format UDTO -o "/tmp/$NAME"
# Remove the sparse bundle:
rm "/tmp/$NAME.sparseimage"
# Rename the ISO and move it to the desktop:
mv "/tmp/$NAME.cdr" "$HOME/Desktop/$NAME.iso"
''', shell=True)
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == 'pbzx': pbzx()
else: main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment