#!/bin/bash
export CWD=$(pwd)
tmp=$(mktemp)
rm -f $tmp ; mkdir $tmp
cd $1
[ -d ./DEBIAN ] || echo "DEBIAN directory not found" && exit 1
export NAME=$(cat DEBIAN/control | grep "Package: " | sed "s/.*: //g")
export ARCH=$(cat DEBIAN/control | grep "Architecture: " | sed "s/.*: //g")
export VERS=$(cat DEBIAN/control | grep "Version: " | sed "s/.*: //g")
tar czvf $tmp/data.tar.gz [a-z]* | sed "s/^/Adding: /g"
cd DEBIAN
tar czf $tmp/control.tar.gz *
cd ../..
echo 2.0 > $tmp/debian-binary
cd $tmp
ar r "${NAME}_${ARCH}_${VERS}.deb" debian-binary control.tar.gz data.tar.gz
mv $tmp/*.deb $CWD/
rm -rf $tmp/
cd $CWD
