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

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_rio.tar.gz

echo "+===================+"
echo "| rio-1.07-modified |"
echo "+===================+"
cd $TMP
tar xzvf $CWD/rio-1.07-modified.tar.gz
cd rio-1.07-modified
make
strip rio
cat rio > $PKG/usr/bin/rio
chmod 755 $PKG/usr/bin/rio
mkdir $PKG/usr/doc/rio-1.07
chown root.root $PKG/usr/doc/rio-1.07
chmod 755 $PKG/usr/doc/rio-1.07
cp -a README CREDITS gpl.txt $PKG/usr/doc/rio-1.07
chown root.root $PKG/usr/doc/rio-1.07/*
chmod 644 $PKG/usr/doc/rio-1.07/*

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/rio.tgz

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/rio-1.07-modified
  rm -rf $PKG
fi
