Skip to content

Instantly share code, notes, and snippets.

@mzyy94
Last active June 30, 2021 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzyy94/3d5ddb930ee6c7ed75c81aa03015c868 to your computer and use it in GitHub Desktop.
Save mzyy94/3d5ddb930ee6c7ed75c81aa03015c868 to your computer and use it in GitHub Desktop.
Patch Apple Silicon support to .pkg installer file
#!/bin/zsh
if [ $# -lt 2 ]; then
echo "Usage: $0 <input.pkg> <output.pkg>"
exit 1
fi
if [ ! -e $1 ]; then
echo "File $1 not found."
exit 1
fi
if [ -e $2 ]; then
echo "Output file $2 already exists."
exit 1
fi
TEMP=$(mktemp -d)
pkgutil --expand $1 $TEMP/extract
HOSTS=$(xmllint --xpath "/installer-gui-script/options/@hostArchitectures" $TEMP/extract/Distribution 2>/dev/null)
if [ ! $? -eq 0 ]; then
echo "Apple Silicon: ❓"
echo "Installer does not contain any installer script. Nothing to do."
rm -rf $TEMP
exit 0
fi
echo $HOSTS | grep -q arm64
if [ $? -eq 0 ]; then
echo "Apple Silicon: ✅"
echo "Installer supports Apple Silicon natively. Nothing to do."
rm -rf $TEMP
exit 0
fi
echo "Apple Silicon: ❌"
echo -e "cd /installer-gui-script/options[1]/@hostArchitectures\nset arm64\nsave" | xmllint --shell $TEMP/extract/Distribution > /dev/null
pkgutil --flatten $TEMP/extract "$2"
echo "Patched installer package has been created."
rm -rf $TEMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment