#!/bin/sh
# required: package "python" version 2.2 or higher installed
VERSION=1.4.2
ARCH=alpha
BUILD=1

PREFIX=/usr

CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-pssh

rm -rf $PKG
mkdir -p $PKG

( cd $TMP
rm -rf pssh-$VERSION
tar xzf $CWD/pssh-$VERSION.tar.gz || exit 1
cd pssh-$VERSION
chown -R root:root .

for binary in bin/* ; do
  # Fix an error from the author
  sed -r 's|basedir\)|basedir + "/lib")|' < $binary > $binary.tmp
  cp $binary.tmp $binary
  rm -f $binary.tmp
done

mkdir -p $PKG/$PREFIX/bin
cp -a bin/* $PKG/$PREFIX/bin/.

for library in psshlib/* ; do
  # This will force removepkg to remove all runtime-compiled *.pyc files
  touch ${library}c
done

mkdir -p $PKG/$PREFIX/lib
cp -a psshlib $PKG/$PREFIX/lib/.

mkdir -p $PKG/$PREFIX/doc/pssh-$VERSION
cp -a AUTHORS BUGS COPYING ChangeLog INSTALL PKG-INFO TODO doc/pssh*html $PKG/$PREFIX/doc/pssh-$VERSION/

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

# Build package:
cd $PKG
makepkg -l y -c n $TMP/pssh-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/pssh.build.log
