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

VERSION=0.17
ARCH=${ARCH:-i486}
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf netwrite-0.17
tar xzvf $CWD/netwrite-0.17.tar.gz || exit 1
cd netwrite-0.17
chown -R root:root .
zcat $CWD/netwrite-0.17.diff.gz | patch -p1 || exit
./configure --prefix=/usr
make || exit 
# The versions in util-linux are better, but we'll keep in.writed just in case:
#cat write > $PKG/usr/bin/write
#cat write.1 | gzip -9c > $PKG/usr/man/man1/write.1.gz
cd writed
strip writed
mkdir -p $PKG/usr/sbin
cat writed > $PKG/usr/sbin/in.writed
chmod 755 $PKG/usr/sbin/in.writed
mkdir -p $PKG/usr/man/man8
cat writed.8 | gzip -9c > $PKG/usr/man/man8/in.writed.8.gz
cd ..
mkdir -p $PKG/usr/doc/netwrite-0.17
cp -a README $PKG/usr/doc/netwrite-0.17
chown root:root $PKG/usr/doc/netwrite-0.17/*
chmod 644 $PKG/usr/doc/netwrite-0.17/*

# Finish up the package:
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/netwrite-$VERSION-$ARCH-$BUILD.tgz