#!/bin/bash


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


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

# Copy things from {WORK}/root into {WORK}/rootDVD
# echo "Collecting files from {WORK}/root"
mkdir -p ${WORK}/rootDVD/usr/local/texlive/2013/
cp -pRf ${WORK}/DVD/texlive.profile ${WORK}/rootDVD/usr/local/texlive/2013/texlive.profile
cp -pRf ${WORK}/DVD/texlivea4.profile ${WORK}/rootDVD/usr/local/texlive/2013/texlivea4.profile
chown root ${WORK}/rootDVD/usr/local/texlive/2013/texlive.profile
chown root ${WORK}/rootDVD/usr/local/texlive/2013/texlivea4.profile

# cp -pRf ${WORK}/root/usr/local/texlive/2013/texmf-config ${WORK}/rootDVD/usr/local/texlive/2013/texmf-config
# cp -pRf ${WORK}/root/usr/local/texlive/2013/texmf-var ${WORK}/rootDVD/usr/local/texlive/2013/texmf-var
# cp -pRf ${WORK}/root/usr/local/texlive/2013/texmf.cnf ${WORK}/rootDVD/usr/local/texlive/2013/texmf.cnf
# chmod
echo "Changing permissions"
chmod -R a+r ${WORK}/rootDVD/usr
chgrp -R wheel ${WORK}/rootDVD/usr

# Ensure target directories we need for applications are present
chmod 755 ${WORK}/rootDVD/usr
chgrp wheel ${WORK}/rootDVD/usr

# Copy the TeXDist Preference Panel
# mkdir  ${WORK}/rootDVD/Library
# mkdir ${WORK}/rootDVD/Library/PreferencePanes
# chmod 1775 ${WORK}/rootDVD/Library
# chmod 775 ${WORK}/rootDVD/Library/PreferencePanes
# chgrp admin ${WORK}/rootDVD/Library
# chgrp admin ${WORK}/rootDVD/Library/PreferencePanes

# echo "Copying TeXDist Preference Panel"
# ditto ${WORK}/PreferencePane/TeXDistPrefPane.prefPane \
# 		${WORK}/rootDVD/Library/PreferencePanes/TeXDistPrefPane.prefPane
# chown -R root ${WORK}/rootDVD/Library/PreferencePanes/TeXDistPrefPane.prefPane

# Copy the format files for PPC
# rm ${WORK}/DVD/resources/dvilualatex.fmt
# rm ${WORK}/DVD/resources/dviluatex.fmt
# rm ${WORK}/DVD/resources/lualatex.fmt
# rm ${WORK}/DVD/resources/luatex.fmt
# ditto ${WORK}/luatex-fmt/dvilualatex.fmt ${WORK}/DVD/resources/dvilualatex.fmt
# ditto ${WORK}/luatex-fmt/dviluatex.fmt ${WORK}/DVD/resources/dviluatex.fmt
# ditto ${WORK}/luatex-fmt/lualatex.fmt ${WORK}/DVD/resources/lualatex.fmt
# ditto ${WORK}/luatex-fmt/luatex.fmt ${WORK}/DVD/resources/luatex.fmt


# Build the package!
# echo "Building the Installer package"
# ./../PackageMaker.app/Contents/MacOS/PackageMaker  -build -p ${WORK}/TeXLive-2013-DVD.pkg -ds -s \
# 	-f ${WORK}/rootDVD -r ${WORK}/DVD/resources -i ${WORK}/DVD/Info.plist -d ${WORK}/DVD/Description.plist

# Build the package!
# echo "Building the Installer package"
#  /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/Packagemaker   --out ${WORK}/TeXLive-2013-DVD.pkg  --target 10.5  \
# 	--root ${WORK}/rootDVD --resources ${WORK}/DVD/resources --id org.tug.mactex.texlive2013-dvd  --verbose --no-recommend  \
#	--root-volume-only --no-relocate --scripts ${WORK}/DVD/scripts


######################################################
# FINALLY, PUT MY /usr/local BACK AS IT WAS
# mv -f /usr/local.save /usr/local
######################################################
