#!/bin/bash

# skey.SlackBuild
# Build s/key client package for a Slackware port.
# by Stuart Winter <stuart@armedslack.org>
# 31-Aug-2004

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$PWD
export PORTCWD=$PWD

# Temporary build locations:
export TMPBUILD=$TMP/build-$PACKAGE
export PKG=$TMP/package-$PACKAGE
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Extract source container:
# I use Mandrake's source (srpm converted) because it was the only version of
# skey I could find that'd compile under Linux without modification.
# This is a bit sloppy really - maybe I should have ripped out the patch and .bz2 file
# but it makes downloading it easier.
tar zxvvf $CWD/sources/$PACKAGE-$VERSION-*.tgz
cd $PACKAGE-$VERSION-*

# Extract source archive:
tar jxvvf $PACKAGE-$VERSION.tar.bz2
cd $PACKAGE-$VERSION
slackhousekeeping

# Apply patches:
bzcat ../skey-shadow-password.patch.bz2 | patch -p1

# Configure:
./configure \
   --prefix=/usr \
   --sysconfdir=/etc || failconfig

# Build:
make || failmake

# Install into package framework:
make install DESTDIR=$PKG || failinstall

# We're only including the client stuff:
( cd $PKG
  rm -rf etc usr/{include,lib,man/man8,etc}
  ( cd usr/bin
    mv skey ..
    rm -f *
    mv ../skey . )
  cd usr/man/man1
  mv skey.1 ..
  rm -f *
  mv ../skey.1 . )

# Install docs:
mkdir -p $PKG/usr/doc/$PACKAGE-$VERSION
cp -a CHANGES INSTALL README *.copyright \
      $PKG/usr/doc/$PACKAGE-$VERSION

# Slackware policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = arm ]; then
   . $PORTCWD/arm/pkger
 else
   makepkg -l y -c n $PKGSTORE/$PKGSERIES/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
fi

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links
