#!/bin/sh
# copy_project  templatePath destPath templateName destName iconFile 
PATH=/usr/ucb:/bin:/usr/bin export PATH

template=$1
destdir=$2
tname=$3
name=$4
icon=$5

echo Copying template from $template to $destdir ...
cp -r $template $destdir
cd $destdir

# OK we have to do change templateName to destName in various files
# in the destination directory.

# 1) Fix up the .iconheader file

echo Fixing $tname.iconheader ...
sed -e "s/$tname/$name/g" <$tname.iconheader >$name.iconheader
rm $tname.iconheader

# 2) Fix up the _main.m file

echo Fixing ${tname}_main.m...
sed -e "s/$tname/$name/g" <${tname}_main.m >${name}_main.m
rm ${tname}_main.m

# 3) Rename the main nib file
# Note that the main menu title in the nib template file should be
# "UNTITLED"; IB changes this to be the same as the name of the nib.

echo Fixing $tname.nib...
mv English.lproj/$tname.nib English.lproj/$name.nib

# 4) Fix up the Makefile

echo Fixing Makefile...
sed -e "s/$tname/$name/g" <Makefile >Makefile.new
mv Makefile.new Makefile

# 5) Set the icon

case "$icon" in
"")	;;
*)
    echo Copying icon...
    cp $icon icon.tiff
    # PB.project may already contain APPICON=foo.tiff - but it might not
    # be there.
    if grep -s APPICON PB.project ; then
	sed -e 's/^APPICON=.*$/APPICON=icon.tiff;/' <PB.project >PB.project.new
	mv PB.project.new PB.project
    else
	echo "APPICON=icon.tiff;" >>PB.project
    fi
	
esac

	
# 6) And finally, fix up the PB.project

echo Fixing PB.project...
sed -e "s/$tname/$name/g" <PB.project >PB.project.new
mv PB.project.new PB.project

echo Copied succesfully.

exit 0
