#!/bin/sh

PRGNAM=vagrant

ARCH=${ARCH:-$(uname -m)}
VERSION=${VERSION:-1.4.3}
BUILD=${BUILD:-1}
TAG=${TAG:-cyco}

# Allow $ARCH to be preset before running the script.  This is useful in the
# case where someone is running a 32-bit chroot environment under an x86_64
# kernel:
case "$ARCH" in
  i?86) LIBDIRSUFFIX="" ; ARCH=i386 ;;
  x86_64) LIBDIRSUFFIX="64" ;;
  *) echo "Package for $(uname -m) architecture is not available." ; exit 1 ;;
esac

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

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $PKG

# Download it by hand...

ar p $CWD/vagrant_${VERSION}_$ARCH.deb data.tar.gz | gunzip | tar xv || exit 1
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# Make sure top-level perms are correct:
chmod 0755 .

mkdir -p $PKG/install
cat <<EOF > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

       |-----handy-ruler----------------------------------------------------|
$PRGNAM: $PRGNAM (Development environments made easy.)
$PRGNAM:
$PRGNAM: Create and configure lightweight, reproducible, and portable
$PRGNAM: development environments.
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM: Homepage:  http://www.vagrantup.com/
$PRGNAM:
EOF

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.txz