Created
December 16, 2021 23:51
-
-
Save pudquick/0cfe9198890681928a1bc74b57b3e3c3 to your computer and use it in GitHub Desktop.
Fix python.org uiversal 2 python 3 packages so they don't trigger Rosetta 2 installs on Apple silicon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
function cleanup { | |
if [ ! -z "$TMPD" ]; then | |
rm -rf "$TMPD" | |
fi | |
} | |
trap cleanup EXIT | |
if [ "$#" -eq 0 ]; then | |
echo "usage: arch_fix /path/to/python.pkg /path/to/save.pkg" | |
exit 0 | |
fi | |
if [ "$#" -ne 2 ]; then | |
echo "error: missing argument(s)\n" | |
echo "usage: arch_fix /path/to/python.pkg /path/to/save.pkg" | |
exit 1 | |
fi | |
# make a temporary directory to unpack to | |
TMPD=`mktemp -d` | |
# for sanity's sake, remove quarantine/extended attributes from package just in case | |
xattr -c "$1" | |
# expand the output to tmp | |
pkgutil --expand "$1" "${TMPD}/out" | |
# patch the Distribution file <options> to include architecture | |
sed -i '' 's/<options /<options hostArchitectures="x86_64,arm64" /g' "${TMPD}/out/Distribution" | |
# flatten the package back to the destination | |
pkgutil --flatten "${TMPD}/out" "$2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment