Skip to content

Instantly share code, notes, and snippets.

@jief666
Last active August 11, 2021 11:14
Show Gist options
  • Save jief666/92f96135aaefe6cfcaeb07602b4802af to your computer and use it in GitHub Desktop.
Save jief666/92f96135aaefe6cfcaeb07602b4802af to your computer and use it in GitHub Desktop.
Command line utility to expand xip archive without intermediary temporary files.
#!/bin/bash
SCRIPT_ABS_FILENAME=`perl -e 'use Cwd "abs_path";print abs_path(shift)' "${BASH_SOURCE[0]:-${(%):-%x}}"`
SCRIPT_DIR=`dirname "$SCRIPT_ABS_FILENAME"`
#to copy/paste cmds in terminal (for debug purpose?), do this before : SCRIPT_DIR=$(pwd)
set -e
set -o pipefail
#Everything in put in a function so return will work even if this script is not sourced
function do_it()
{
if [ -z "$1" ]
then
echo "Usage: unxip {path to xip file} {destination dir}
return 1
fi
if [ -z "$2" ]
then
echo "Usage: unxip {path to xip file} {destination dir}
return 1
fi
xip_file="$1"
dest_dir="$2"
if ! [ -f "$xip_file" ]
then
echo "File \'$xip_file\' doesn't not exist"
return 2
fi
if ! [ -d "$dest_dir" ]
then
echo "Dir \'$dest_dir\' doesn't not exist"
return 3
fi
"$SCRIPT_DIR"/xar -xf "$xip_file" --to-stdout --exclude=Metadata | "$SCRIPT_DIR"/pbzx-1.0.2 -n /dev/stdin | (cd "$dest_dir" && cpio -i)
#there is a lot of messages like :
# ./Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/sys/un.h: Can't create 'Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/sys/un.h'
# looks like they are created anyway ??!
}
do_it "$@"
#TODO before : Install Xcode in default location (/Applications). Run Xcode to agree license and finish setup.
@jief666
Copy link
Author

jief666 commented Aug 11, 2021

Put these 3 files in any folder of your choice.
Launch in terminal :
{path to unxip}/unxip {path to xip file} {path to expand in}

Example : /usr/local/bin/unxip /tmp/Xcode_12.5.xip /Applications

@jief666
Copy link
Author

jief666 commented Aug 11, 2021

I did this to be able to expand xip with expired certificates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment