#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-quota

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/_quota.tar.gz

echo "+============+"
echo "| quota-2.00 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/quota-2.00.tar.gz
cd quota-2.00
zcat $CWD/quota.reiserfs.diff.gz | patch -p1 --verbose --backup --suffix=.orig
./configure \
   --prefix=/usr \
   i386-slackware-linux
make
make mo
strip quotacheck quotaon edquota repquota warnquota quotastats setquota quota
cat quotacheck > $PKG/sbin/quotacheck
cat quotaon > $PKG/sbin/quotaon
for file in edquota repquota warnquota quotastats setquota ; do
  cat $file > $PKG/usr/sbin/$file
done
cat quota > $PKG/usr/bin/quota
cat rquota.h > $PKG/usr/include/rpcsvc/rquota.h
cat rquota.x > $PKG/usr/include/rpcsvc/rquota.x
mkdir -p $PKG/etc
cat warnquota.conf > $PKG/etc/warnquota.conf-sample
for page in *.1 ; do
  cat $page | gzip -9c > $PKG/usr/man/man1/$page.gz
done
for page in *.2 ; do
  cat $page | gzip -9c > $PKG/usr/man/man2/$page.gz
done
for page in *.3 ; do
  cat $page | gzip -9c > $PKG/usr/man/man3/$page.gz
done
for page in *.8 ; do
  cat $page | gzip -9c > $PKG/usr/man/man8/$page.gz
done
# This stuff is in nfs-utils already:
rm -f $PKG/usr/man/man8/rquotad.8.gz
mkdir -p $PKG/usr/share/locale/pl/LC_MESSAGES
cat po/pl.mo > $PKG/usr/share/locale/pl/LC_MESSAGES/quota.mo
mkdir -p $PKG/usr/doc/quota-2.00
cp -a Changelog README.gettext doc $PKG/usr/doc/quota-2.00
chown -R root.root $PKG/usr/doc/quota-2.00

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

# Warn of zero-length files:
for file in `find . -type f -print` ; do
 if [ "`filesize $file`" = "0" ]; then
  echo "WARNING: zero length file $file"
 fi
 if [ "`filesize $file`" = "20" ]; then
  echo "WARNING: possible empty gzipped file $file"
 fi
done

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