#!/bin/bash
#
# Copyright 2005-2020 The Mumble Developers. All rights reserved.
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.

cp libmumbleoverlay.dylib MumbleOverlay.osax/Contents/MacOS/

productbuild \
	--component MumbleOverlay.osax /Library/ScriptingAdditions \
	synth.pkg

root=$(mktemp -d -t mumble-overlay-installer)
/usr/bin/xar -f synth.pkg -x -C ${root}
mkdir -p ${root}/Resources
mv bg.png ${root}/Resources/
VERSION=`/usr/libexec/PlistBuddy -c "print MumbleOverlayVersion" MumbleOverlay.osax/Contents/Info.plist`
MINCLIENT=`/usr/libexec/PlistBuddy -c "print MumbleOverlayMinMumbleVersion" MumbleOverlay.osax/Contents/Info.plist`
echo "<upgrade version=\"${VERSION}\" minclient=\"${MINCLIENT}\" />" > ${root}/upgrade.xml

sed -i '' -e 's,<installer-gui-script minSpecVersion="1">,<installer-gui-script minSpecVersion="1"><title>Mumble Overlay</title><background mime-type="image/png" file="bg.png" />,' ${root}/Distribution

pushd ${root}
/usr/bin/xar -f MumbleOverlay.pkg --no-compress "^.*$" -c ./*
popd

cp ${root}/MumbleOverlay.pkg MumbleOverlay.pkg
