#!/bin/bash


# We're going to run this in the MacTeXDVD working directory...
WORK=`pwd`

echo "Removing old file tree at ${WORK}/root"
rm -rf ${WORK}/root

# Copy everything from UniversalConvert into our root
echo "Collecting files from Universal"
mkdir -p ${WORK}/root/usr/local/bin
mkdir -p ${WORK}/root/usr/local/lib
mkdir -p ${WORK}/root/usr/local/etc
mkdir -p ${WORK}/root/usr/local/share/man/man1
chmod -R 755 ${WORK}/root/usr
cp -pRf ${WORK}/Universal/local/bin/convert ${WORK}/root/usr/local/bin/convert
cp -pRf ${WORK}/Universal/local-i386/lib/ImageMagick-6.8.3 ${WORK}/root/usr/local/lib/ImageMagick-6.8.3
cp -pRf ${WORK}/Universal/local-i386/etc/ImageMagick ${WORK}/root/usr/local/etc/ImageMagick
cp -pRf ${WORK}/Universal/local-i386/share/man/man1/convert.1 ${WORK}/root/usr/local/share/man/man1/convert.1

# chmod
echo "Changing permissions"
chmod -R a+r ${WORK}/root/usr
# Ensure owner and group are correct
chown -R root ${WORK}/root/usr
chgrp -R wheel ${WORK}/root/usr

# Build the package!
# echo "Building the Installer package"
# ./../PackageMaker.app/Contents/MacOS/PackageMaker  -build -p ${WORK}/ImageMagick-Convert-6.7.6-0.pkg -ds -s \
# 	-f ${WORK}/root -r ${WORK}/resources -i ${WORK}/Info.plist -d ${WORK}/Description.plist

# echo "Building the Installer package"
#  /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/Packagemaker   --out ${WORK}/ImageMagick-Convert-6.7.6-0.pkg  --target 10.5  \
# 	--root ${WORK}/root --resources ${WORK}/resources --id org.tug.mactex.imagemagick-convert-6.7.6-0  --verbose --no-recommend  \
# 	--root-volume-only --no-relocate --scripts ${WORK}/scripts


