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

VERSION=2.05a
ARCH=i386
BUILD=2

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

echo "+===========+"
echo "| bash-$VERSION |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/bash-$VERSION.tar.gz
cd bash-$VERSION
CFLAGS=-O2 ./configure --prefix=/usr i386-slackware-linux
make
strip bash
cat bash > $PKG/bin/bash2.new
# We don't include the "bashbug" script.
mkdir -p $PKG/usr/doc/bash-$VERSION
cp -a AUTHORS CHANGES COMPAT COPYING INSTALL MANIFEST NEWS NOTES \
  README Y2K doc/FAQ doc/INTRO $PKG/usr/doc/bash-$VERSION
( cd $PKG/usr/doc/bash-$VERSION
  chown root.root *
  chmod 644 * )
cd doc
groff -ms -Tascii article.ms > $PKG/usr/doc/bash-$VERSION/article.txt
for page in bash.1 builtins.1 rbash.1 ; do
  cat $page | gzip -9c > $PKG/usr/man/man1/$page.gz
done
cat bashref.info | gzip -9c > $PKG/usr/info/bash.info.gz
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/bash-$VERSION-$ARCH-$BUILD.tgz

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