pdfm_pkg/build_pkg.sh
2022-12-17 11:37:06 +08:00

48 lines
2.0 KiB
Bash

#!/bin/bash
set -e
TMPDIR=`mktemp -d`
function cleanup()
{
echo " * Cleaning Up..."
hdiutil detach "${TMPDIR}/mnt" -quiet >/dev/null 2>&1 || true
rm -rf "${TMPDIR}" || true
}
trap cleanup EXIT
if [ -z "$1" ]
then
echo " * Getting latest version..."
PD_VER=`python3 script/get_latest_version.py`
echo " * Latest version: ${PD_VER}"
else
PD_VER="$1"
echo " * Selected version: ${PD_VER}"
fi
PD_URL="https://download.parallels.com/desktop/v${PD_VER%%.*}/${PD_VER}/ParallelsDesktop-${PD_VER}.dmg"
echo " * Downloading DMG..."
wget -q --show-progress -O "${TMPDIR}/ParallelsDesktop-${PD_VER}.dmg" "${PD_URL}" || { echo "Download failure!"; exit 1; }
echo " * Extracting app from DMG..."
mkdir -p "${TMPDIR}/mnt" && hdiutil attach "${TMPDIR}/ParallelsDesktop-${PD_VER}.dmg" -quiet -mountpoint "${TMPDIR}/mnt" -noverify -nobrowse
mkdir -p "${TMPDIR}/payload" && ditto "${TMPDIR}/mnt/Parallels Desktop.app" "${TMPDIR}/payload/Parallels Desktop.app"
hdiutil detach "${TMPDIR}/mnt" -quiet && rmdir "${TMPDIR}/mnt"
xattr -d com.apple.FinderInfo "${TMPDIR}/payload/Parallels Desktop.app"
chflags nohidden "${TMPDIR}/payload/Parallels Desktop.app"
echo " * Patching..."
python3 script/gen_patch_script.py "${PD_VER}" "${TMPDIR}/payload/Parallels Desktop.app/Contents/MacOS/Parallels Service.app/Contents/MacOS/prl_disp_service" "${TMPDIR}"
echo " * Creating PKG..."
pkgbuild --quiet --analyze --root "${TMPDIR}/payload" "${TMPDIR}/component.plist"
plutil -replace BundleIsRelocatable -bool NO "${TMPDIR}/component.plist"
plutil -replace BundleIsVersionChecked -bool NO "${TMPDIR}/component.plist"
plutil -replace BundleHasStrictIdentifier -bool NO "${TMPDIR}/component.plist"
plutil -replace BundleOverwriteAction -string upgrade "${TMPDIR}/component.plist"
pkgbuild --quiet --root "${TMPDIR}/payload" --install-location "/Applications/" --component-plist "${TMPDIR}/component.plist" --scripts "${TMPDIR}/scripts" "./ParallelsDesktop-${PD_VER}.pkg"
cleanup && trap - EXIT
echo " * Done!"