#!/bin/bash

REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
source $REPO_DIR/script/bootstrap

sudo rm -rf $BUILD_DIR/bundles
mkdir -p $BUILD_DIR

xcodebuild -scheme SoftU2F install DSTROOT=$BUILD_DIR/bundles

cd $BUILD_DIR

# The installer would fail if we included these because /System and /usr cannot
# be written to. Not sure how to prevent them from being created in the first
# place.
rm -rf ./bundles/System
rm -rf ./bundles/usr

pkgbuild --analyze --root ./bundles/ SoftU2F.plist
pkgbuild --sign "Developer ID Installer: GitHub" --identifier com.GitHub.SoftU2F --root ./bundles/ --scripts ../install-scripts --component-plist ./SoftU2F.plist ./SoftU2F.pkg
