How to extract xip archive using command line?
Asked Answered
E

8

28

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.

Escargot answered 4/11, 2016 at 3:4 Comment(2)
Possible duplicate of Extract .xip files into a specific folderDoddering
Having asnwered both: I am in favor of removing this as a dupe as well. I have cleaned up the other question and believe it should suffice.Doddering
E
8
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.

Escargot answered 4/11, 2016 at 3:33 Comment(4)
This is undesirable from a CI point of view since it requires installing a third party app when native tools (/System/Library/CoreServices/Applications/Archive Utility.app/Contents/MacOS/Archive Utility) installed on the system already perform the work.Albano
@Albano from a CI point of view: how can the Archive Utility be feasibly integrated into a shell script to achieve automation? Can it be scripted? Or did you think of double-clicking the XIP archive?Shitty
@Shitty if you just do open -W archive.xip from terminal that will launch bomArchiveHelper and unpack the xip in the current directory and will block until the unarchive is complete. I use this to open Xcode.xip via a shell call in Jenkins all the time. The -W flag tells the shell to wait for the application invoked to exit before proceeding.Albano
Upvoted, but see below for an easier solution: brew install thii/unxip/unxip also unxips correctly Xcode archives, unlike Apple tools. (but it needs compilation of the pbzx tool from source, which needs to also build a custom lib....)Samale
D
40

You could try:

xip -x [path to .xip file]

Doddering answered 13/6, 2018 at 11:18 Comment(1)
This is the way.Umbria
H
14

On macOS Mojave (not sure about other OS versions), navigate to the directory into which you’d like to expand the contents, then run xip --expand /path/to/xip.xip. For instance:

iMac:Applications jeff$ xip --expand /Users/jeff/Downloads/Xcode_11_Beta.xip
Higginson answered 16/6, 2019 at 21:39 Comment(2)
I've just checked that in macOS High Sierra (10.13.6) this command works as well, although not mentioned in 'man xip', curiously. I had some authentication issue which re-downloading the file from developer.apple.com cleared it.Furred
I can confirm that xip --expand works in 10.12 Sierra & 10.11 El Capitan as well, even though it wasn't added to the man page until macOS 10.14.Inexplicit
E
8
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.

Escargot answered 4/11, 2016 at 3:33 Comment(4)
This is undesirable from a CI point of view since it requires installing a third party app when native tools (/System/Library/CoreServices/Applications/Archive Utility.app/Contents/MacOS/Archive Utility) installed on the system already perform the work.Albano
@Albano from a CI point of view: how can the Archive Utility be feasibly integrated into a shell script to achieve automation? Can it be scripted? Or did you think of double-clicking the XIP archive?Shitty
@Shitty if you just do open -W archive.xip from terminal that will launch bomArchiveHelper and unpack the xip in the current directory and will block until the unarchive is complete. I use this to open Xcode.xip via a shell call in Jenkins all the time. The -W flag tells the shell to wait for the application invoked to exit before proceeding.Albano
Upvoted, but see below for an easier solution: brew install thii/unxip/unxip also unxips correctly Xcode archives, unlike Apple tools. (but it needs compilation of the pbzx tool from source, which needs to also build a custom lib....)Samale
P
8

Use unxip. You can install it with Homebrew:

brew install thii/unxip/unxip

To extract a .xip file:

unxip path/to/.xip
Parma answered 5/8, 2018 at 7:49 Comment(3)
Unxiping XCode 10.1 was not working with Unarchiver... but this did the trick, thanks!Samale
this save me countless hours of frustrations. thanks. I used this to extract Xcode_12.5.1.xipOat
@IeeCoder It's been stuck for me on Expanding items from “Xcode_12.5.1.xip”: 99% for quite a while now. shall I give up? (what's wrong with that xip? no tool to extract it...)Wehner
A
6

open -W archive.xip will work better since it will then block until the archive has finished opening.

Albano answered 4/12, 2017 at 17:12 Comment(0)
P
0

On MacOS Monterey 12.7 the following worked for me:

  1. Download the
  2. Extract xip archive: xip --expand ~/Downloads/Xcode_14.3.1.xip
  3. Ignore warning message xip: signing certificate was "Software Update" (validation not attempted)
  4. Wait a very very long time for archive to extract with no feedback (I did it overnight)
  5. Move expanded folder to /Applications: sudo mv Xcode.app /Applications
  6. To run Xcode you must use full path to executable or lese you will get an error: /Applications/Xcode.app/Contents/MacOS/Xcode
Pekingese answered 4/10, 2023 at 15:50 Comment(0)
I
-1

In my case, i used unxip

brew install unxip

Then extract

unxip <Path-To-The-.xip-File>
Itis answered 30/4, 2023 at 3:33 Comment(1)
Please do not post duplicate answers.Peeved
T
-3

You could just run:

open archive.xip
Tref answered 11/9, 2017 at 20:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.