Last active
September 20, 2017 17:33
-
-
Save MagerValp/e2ff35ee1bb7101a7ce558d5f6f94fdf to your computer and use it in GitHub Desktop.
Create standalone firmware update pkg for use with Imagr
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/bash | |
set -o errexit | |
PKG_NAME="FWUpdate" | |
PKG_ID="se.gu.it.FWUpdateStandalone.pkg" | |
datestamp=$( date "+%Y%m%d" ) | |
PKG_VERSION="1.0.$datestamp" | |
USAGE="Usage: $0 path/to/installer.app output_dir" | |
if [[ ! -f "$1/Contents/SharedSupport/InstallESD.dmg" ]]; then | |
echo "$USAGE" | |
exit 64 | |
fi | |
if [[ ! -d "$2" ]]; then | |
echo "$USAGE" | |
exit 64 | |
fi | |
installerapp="$1" | |
outputdir="$2" | |
tmpdir=$(mktemp -d -t fwupdate) | |
remove_tmpdir() { | |
rm -rf "$tmpdir" | |
} | |
trap remove_tmpdir EXIT | |
echo "* Mounting InstallESD" | |
out=$( hdiutil attach -noverify -mountrandom /private/tmp "$installerapp/Contents/SharedSupport/InstallESD.dmg" ) | |
esdmount=$( echo "$out" | grep /private/tmp | cut -f3 ) | |
unmount_esd() { | |
echo "* Unmounting InstallESD" | |
hdiutil detach "$esdmount" | |
} | |
trap unmount_esd EXIT | |
echo "* Expanding firmware package" | |
expandedpkg="$tmpdir/expandedfw_pkg" | |
pkgutil --expand "$esdmount/Packages/FirmwareUpdate.pkg" "$expandedpkg" | |
echo "* Copying firmware update resources" | |
script_dir="tmpdir/scripts" | |
mkdir -p "$script_dir" | |
cp "$expandedpkg"/Scripts/postinstall_actions/update "$script_dir"/postinstall | |
printf '\n\nexit 0\n' >> "$script_dir"/postinstall | |
cp -R "$expandedpkg"/Scripts/Tools "$script_dir"/ | |
echo "* Creating $PKG_NAME-$datestamp.pkg" | |
pkgbuild --nopayload --scripts "$script_dir" --identifier "$PKG_ID" --version "$PKG_VERSION" "$outputdir/$PKG_NAME-$datestamp.pkg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment