#!/bin/bash

# nn.build
# Build nn for Slackware
# Based on original Slackware build scripts,
# Modified by Stuart Winter <stuart@armedslack.org>
# 30-Sep-2004

VERSION=$1

# Extract source:
cd $SLACKTRACKSCRATCHDIR
tar jxvvf $CWD/$PACKAGE-$VERSION.tar.bz2
cd $PACKAGE-$VERSION
slackhousekeeping

# Apply patches:
zcat $CWD/nn.diff.gz | patch -p1 --verbose --backup --suffix=.orig || failpatch
zcat $CWD/nn.badnntphost.diff.gz | patch -p1 --verbose --backup --suffix=.orig || failpatch

# Configure:
cp config.h-dist config.h

# Build:
# A little hack.  For some reason on ARMedslack, sed isn't producing
# the ymakefile properly; it's missing the tabs before the commands
# I need to look at this.  But for the time being I'll use a working
# ymakefile from a Slackware x86 box.
#cp -f $PORTCWD/ymakefile .
make all || failmake

# Install onto filesystem:
./inst s
zcat $CWD/nntpserver.gz > /etc/nntpserver.new

# Copy docs:
mkdir -p /usr/doc/$PACKAGE-$VERSION/contrib
cp -fa INSTALLATION README \
      /usr/doc/$PACKAGE-$VERSION
# This might be useful, so we'll put it in the docs just in case:
cp -a $CWD/NNTP.gz \
      /usr/doc/$PACKAGE-$VERSION
  gzip -d /usr/doc/nn-$VERSION/NNTP.gz
( cd contrib ; cp -a \
  README aspell cn howto-metamail mail-alias nn_elm nn-use-mh nnsum recmail.c recmail.sh \
  /usr/doc/$PACKAGE-$VERSION/contrib )

# Replace with symlinks:
( cd $SLACKTRACKFAKEROOT
  # In Slackware's .tgz, the man pages are owned by news:news but 
  # I see no good reason for this and I don't like it, so:
  chown -R root:root .
  cd usr/bin
  rm -f nnadmin  && ln -sf nn nnadmin
  rm -f nnbatch  && ln -sf nn nnbatch
  rm -f nncheck  && ln -sf nn nncheck
  rm -f nngoback && ln -fs nn nngoback
  rm -f nngrep   && ln -sf nn nngrep
  rm -f nnpost   && ln -sf nn nnpost
  rm -f nntidy   && ln -sf nn nntidy
  rm -f nnview   && ln -sf nn nnview  )

# Install package description:
cd /
slackdesc
