Created
April 14, 2021 04:26
-
-
Save yellowcrescent/cd27604c6ab424c99caa673d45224a10 to your computer and use it in GitHub Desktop.
Extracting MacOS pkg files on Linux
This file contains hidden or 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/bash | |
# | |
# Super basic MacOS .pkg file extractor using p7zip & cpio | |
# @yellowcrescent | |
# | |
# Usage: xpkg.sh MyPkg.pkg /path/to/output/dir | |
# | |
ZBIN=7z | |
PLFILE="Payload~" | |
SRCPKG="$1" | |
OUTDIR=$(readlink -m "${2:-.}") | |
if [[ -z "${SRCPKG}" || "${SRCPKG}" == "-h" || "${SRCPKG}" == "--help" ]]; then | |
echo "usage: $0 INPUT_PKG.pkg [OUTPUT_DIR]" | |
exit 2 | |
fi | |
if [[ ! $(which ${ZBIN}) ]]; then | |
echo "7-zip is not installed (command ${ZBIN} not found). Try installing p7zip-full or similar package." | |
exit 3 | |
fi | |
# Requires the full version of 7-zip (eg. "p7zip-full" or similar) | |
$ZBIN x "${SRCPKG}" "-o${OUTDIR}" | |
if [[ "$1" != 0 ]]; then | |
echo "Extraction failed." | |
fi | |
# Extract payload via cpio if it exists | |
CPIOFILE="${OUTDIR}/${PLFILE}" | |
if [[ -e "${CPIOFILE}" ]]; then | |
cpio -idmv -F "${CPIOFILE}" -D "${OUTDIR}" | |
fi | |
echo "Complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment