#!/bin/sh

# PkgFrontBase
# All
#
# Created by Svend Bodilsen on 4010/9/11.
# Copyright 2011 Frontbase Inc. All rights reserved.
set -x

suffix=""
kind=$1
test -z "$kind" && kind=system
test "${kind}" = "user" && suffix="Personal Edition "

ostarget=`expr "$CONFIGURATION" : "^.*-\(10\..*\)"`

rm -rf ${ProductPackageDir}

mkdir -p ${ProductPackageDir}
cd ${ProductPackageDir}

/bin/sh ${SRCROOT}/../Tools/CollectTools.sh "./Tools"

# Installer resource
mkdir -p Resources
/bin/cp -p ${SRCROOT}/../All/License.rtf       ./Resources/License.rtf
/bin/cp -p ${SRCROOT}/../All/Background.png     ./Resources/Background.png
/bin/cp -p ${SRCROOT}/../Tools/ReadmeTools.rtf ./Resources/ReadMe.rtf
touch ./Resources/Welcome.rtfd  # Placeholder - productbuild does not like directories

rm -rf FrontBaseManager.pkg

# Build the FrontBase package
pkgbuild      --component-plist  ${SRCROOT}/../Tools/Components.plist --root "./Tools" --version "${CURRENT_PROJECT_VERSION}" --identifier com.frontbase.FrontBaseManager --install-location / FrontBaseTools.pkg

#productbuild --component FrontBase/Applications/FrontBaseManager.app  --resources Resources ${TARGET_BUILD_DIR}/FrontBaseManager.pkg

productbuild  --distribution ${SRCROOT}/../Tools/Distribution  --package-path . --version "${CURRENT_PROJECT_VERSION}" --resources Resources  ${TARGET_BUILD_DIR}/FrontBaseTools.pkg

# Productbuild does not like directories - so replace the placeholder with the welcome.rtfd
mkdir -p Repackage
cd Repackage
xar -xf ${TARGET_BUILD_DIR}/FrontBaseTools.pkg
rm -rf Resources/Welcome.rtfd
/bin/cp -rp ${SRCROOT}/../All/Welcome.rtfd Resources
xar -cf ${TARGET_BUILD_DIR}/FrontBaseTools.pkg  --no-compress ".*" *
cd ..

#rm -rf ${ProductPackageDir}
