export DEB=$3

if [ $1 = "other" ]; then
  export DISTV=0
  export DISTRO=~$1
else
  export DISTV=0
  export DISTRO=
fi;

if [ "$2" = "release" ]; then
  REL=stable
  OTHER_REL=beta
else
  REL=beta
  OTHER_REL=stable
fi

ARCH_DEB=$(uname -m | sed -e s/i.86/i386/ | sed -e s/x86_64/amd64/)
VERS=$(perl -pe 'if (/^VERSION.*"([^"]+)"/) {$_=$1;} else {$_="";}' <qubx_hjcfit/qubx_plugin_init.py)

mkdir -p $DEB/DEBIAN
cat >|$DEB/DEBIAN/control <<EOF
Package: qub-express-hjcfit-$REL
Version: $VERS.$DISTV-1$DISTRO
Section: science
Priority: optional
Architecture: ${ARCH_DEB}
Enhances: qub-express-$REL (>= 0.7.3), qub-express-$OTHER_REL (>= 0.7.3)
Maintainer: Chris Nicolai <qub@www.qub.buffalo.edu>
Description: QUB Express plugin providing HJCFIT from DCPROGS at UCL
 from www.qub.buffalo.edu
EOF

cat >|$DEB/DEBIAN/postinst <<EOF
#!/bin/sh
python -m compileall /usr/share/qub-express/Plugins/qubx_hjcfit
EOF
chmod 755 $DEB/DEBIAN/postinst

fakeroot dpkg-deb --build $DEB
mv $DEB.deb qub-express-hjcfit-${REL}_$VERS.$DISTV-1${DISTRO}_$ARCH_DEB.deb 



