#!/bin/sh

# Slackware build script for info2man

# Written by B. Watson (yalhcru@gmail.com)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# The version number below is the modification time of the newest file
# in the source tarball.

# 20140907 bkw: original site blocks downloads based on user-agent. Host
# the src on my own server. Only the .info file changed, not the script, so
# didn't bump the BUILD.
# Original download link: http://www.cskk.ezoshosting.com/cs/css/info2man.tar.gz

PRGNAM=info2man
VERSION=${VERSION:-20040717}
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

PERLMODDIR=/usr/share/info2pod

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
mkdir -p $PRGNAM-$VERSION
cd $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM.tar.gz
chown -R root:root .
find -L . \
 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  -o -perm 511 \) -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

# make the script use its own private perl module dir, so we don't
# pollute /usr/lib/perl5.
sed -i -e '2iuse lib "'$PERLMODDIR'";' info2pod

# this uses an ancient Perl 4 module called flush.pl. The damn thing is less
# than 1KB in size, so I included it in the SlackBuild tarball. It came from
# here: http://www.opensource.apple.com/source/perl/perl-21/perl/lib/flush.pl

mkdir -p $PKG/usr/bin $PKG/$PERLMODDIR
install -m0755 -oroot -groot $PRGNAM $PKG/usr/bin
install -m0755 -oroot -groot info2pod $PKG/usr/bin
install -m0644 -oroot -groot $CWD/flush.pl $PKG/$PERLMODDIR
cp -r cs $PKG/$PERLMODDIR/cs

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/README > $PKG/usr/doc/$PRGNAM-$VERSION/README
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}