#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-bsdlpr
SRC=/devel/manpagesrc
INFO=/devel/info-pages/usr/info
TEX=/devel/texinfo-docs

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_bsdlpr.tar.gz

echo "+=========+"
echo "| BSD lpr |"
echo "+=========+"
cd $TMP
tar xzvf $CWD/lpr_5.9-13.tar.gz
cd lpr-5.9
zcat $CWD/lpr_5.9-13.diff.gz | patch
( cd lprm ; zcat $CWD/lprm.diff.gz | patch )
make
cd lpc
cat lpc > $PKG/usr/sbin/lpc
cat lpc.8 | gzip -9c > $PKG/usr/man/man8/lpc.8.gz
cd ../filters
cat lpf > $PKG/usr/sbin/lpf
cd ../lpd
cat lpd > $PKG/usr/sbin/bsdlpd
cat lpd.8 | gzip -9c > $PKG/usr/man/man8/lpd.8.gz
cd ../lpq
cat lpq > $PKG/usr/bin/lpq
cat lpq.1 | gzip -9c > $PKG/usr/man/man1/lpq.1.gz
cd ../lpr
cat lpr > $PKG/usr/bin/lpr
cat lpr.1 | gzip -9c > $PKG/usr/man/man1/lpr.1.gz
cd ../lprm
cat lprm > $PKG/usr/bin/lprm
cat lprm.1 | gzip -9c > $PKG/usr/man/man1/lprm.1.gz
cd ../lptest
cat lptest > $PKG/usr/sbin/lptest
cat lptest.1 | gzip -9c > $PKG/usr/man/man1/lptest.1.gz
cd ../pac
cat pac > $PKG/usr/sbin/pac
cat pac.8 | gzip -9c > $PKG/usr/man/man8/pac.8.gz
cd ..
cat printcap.5 | gzip -9c > $PKG/usr/man/man5/printcap.5.gz
strip $PKG/usr/bin/*
strip $PKG/usr/sbin/*

# Build the package:
cd $PKG
tar czvf $TMP/bsdlpr.tgz .

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/lpr-5.9
  rm -rf $PKG
fi