#! /bin/ksh

if [ -z "$1" ]; then
  echo "ERROR: Invoke with path to packaging dist tree root"
  exit 1
fi

if [ ! -d $1/dist ]; then
  echo "ERROR: no dist/ directory"
  exit 1
fi

if [ ! -d $1/input ]; then
  mkdir $1/input
fi

if [ ! -f $1/Makefile ]; then
  cp -f Makefile $1/Makefile
fi

if [ ! -d $1/dist/apache/etc ]; then
  mkdir $1/dist/apache/etc
  cp apache.etc $1/dist/apache/etc/apache
fi

if [ ! -d $1/dist/apache/usr/share ]; then
  T=`pwd`/apdoc.tar
  (cd $1/dist/apache/usr; tar xf $T)
fi

cp -f httpd.conf.default $1/dist/apache/usr/lib/apache/conf

if [ -d $1/dist/apache/usr/lib/apache/htdocs ]; then
  cp -f index.html.en $1/dist/apache/usr/lib/apache/htdocs
elif [ -d $1/dist/apache/usr/lib/apache/htdocs-default ]; then
  cp -f index.html.en $1/dist/apache/usr/lib/apache/htdocs-default
fi

if [ ! -d $1/dist/php4/usr/lib/apache/manual/images ]; then
  mkdir -p $1/dist/php4/usr/lib/apache/manual/images
  cp php.gif $1/dist/php4/usr/lib/apache/manual/images
fi

if [ ! -d $1/dist/modperl/usr/lib/apache/manual/images ]; then
  mkdir -p $1/dist/modperl/usr/lib/apache/manual/images
  cp mod_perl.gif $1/dist/modperl/usr/lib/apache/manual/images
fi

for i in AxKit apache modperl modssl perlASP php4; do
  if [ ! -d $1/dist/$i/cntl ]; then
    mkdir -p $1/dist/$i/cntl
    cp $i/cntl/* $1/dist/$i/cntl/
  fi
done

mkcdmt -d $1 -P Apache -D "Apache Web Server 1.3.29" -V 5.0.7Gd -E -p apache.mkcdmt
