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

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

echo "+============+"
echo "| socket-1.1 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/socket-1.1.tar.gz
cd socket-1.1
make clean
zcat $CWD/globals.h.diff.gz | patch
make
strip socket
cat socket > $PKG/usr/bin/socket
cat socket.1 | gzip -9c > $PKG/usr/man/man1/socket.1.gz
cp -a BLURB README CHANGES README.HPLJ COPYRIGHT README.LINUX \
   Dependencies INSTALL $PKG/usr/doc/socket-1.1
chown -R root.root $PKG/usr/doc/socket-1.1/*
chmod 644 $PKG/usr/doc/socket-1.1/*

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/socket.tgz

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