Search code examples
xcodemacosxcode8osx-elcapitanmacos-sierra

How to extract xip archive using command line?


I searched around how to extract XIP archive using command line with no luck so I am leaving my own solution, as a bash function, here.

I found my inspiration here.


Solution

  • function unxip()
    {
        [ -z "$1" ] && echo "usage: unxip /path/to/archive.xip" && return
    
        # http://newosxbook.com/src.jl?tree=listings&file=pbzx.c
        PBZX="/usr/local/src/pbzx/pbzx" && [ ! -x "$PBZX" ] && echo "$PBZX not found." && return
    
        [ ! -f "$1" ] && echo "$1 not found." && return
    
        [ -f "Content" ] || [ -f "Metadata" ] && echo "Content or Metadata already exists." && return
    
        pkgutil --check-signature "$1" && xar -xf "$1" && "$PBZX" Content | sudo tar x --strip-components=1
    
        rm "Content" "Metadata"
    }
    

    We first check for xip file signature then extract its contents using xar. We then use Jonathan Levin pbzx to properly unpack pbzx chunks and pipe the output to tar, skipping . to avoid overwriting current working directory permissions.

    This does the trick to unpack Xcode8.xip archives on OS X El Capitan.