export DEB=$3

if [ $1 = "hardy" ]; then
  export DISTV=1
  export DISTRO=~$1
elif [ $1 = "intrepid" ]; then
  export DISTV=2
  export DISTRO=~$1
elif [ $1 = "jaunty" ]; then
  export DISTV=3
  export DISTRO=~$1
elif [ $1 = "karmic" ]; then
  export DISTV=4
  export DISTRO=~$1
elif [ $1 = "lucid" ]; then
  export DISTV=5
  export DISTRO=~$1
elif [ $1 = "maverick" ]; then
  export DISTV=6
  export DISTRO=~$1
elif [ $1 = "natty" ]; then
  export DISTV=7
  export DISTRO=~$1
elif [ $1 = "oneiric" ]; then
  export DISTV=8
  export DISTRO=~$1
elif [ $1 = "lisa" ]; then
  export DISTV=8
  export DISTRO=~oneiric
elif [ $1 = "precise" ]; then
  export DISTV=9
  export DISTRO=~$1
elif [ $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_macroscopic/qubx_plugin_init.py)

mkdir -p $DEB/DEBIAN
cat >|$DEB/DEBIAN/control <<EOF
Package: qub-express-macroscopic-$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 to analyze ensemble recordings of molecules such as ion channels.
 from www.qub.buffalo.edu
EOF

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

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



