Skip to content

Instantly share code, notes, and snippets.

@mzyy94
Last active Jun 30, 2021
Embed
What would you like to do?
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