#!/bin/sh
#---------------------------------------------------------------------
#
#	MUG is Maemo by/for Uber-Geeks - a collection of tools and
#	utilities for the Nokia770 by Uber-Geeks.com
#
#	mug-packager.sh v0.1 [2005feb15]
#
#	Unless otherwise documented in the code, this software
#	has been released under the GNU General Public License
#	and is copyright mug@uber-geeks.com.
#
#	More information about the GPL can be found on the GNU website.
#
#	All of this software is considered to be "stable". However,
#	it is always a good idea to test and/or review code before
#	relying on it. There is no warranty for this code beyond what
#	is required by the GPL. 
#
#	usage mug-packager.sh packagename builddir
#
#	author mug@uber-geeks.com	
#
#---------------------------------------------------------------------
#
#	test for input parameters
#
if [ -z $1 -o -z $2 ] ; then
	echo
	echo "mug-packager v0.1[2005Feb15] GPL2"
	echo
	echo "usage: mug-packager.sh packagename builddir"
	echo
	exit 1 ;
fi
#
#	test if source dir is valid
#
if [ ! -d $2 ] ; then
	echo $2 " build dir not found - aborting"
	exit 1 ;
fi
#
#	test if debian control directory is there
#
if [ ! -d $2/DEBIAN ] ; then
	echo $2/DEBIAN " control dir not found - Directory structure appears invalid - aborting"
	exit 1 ;
fi
#
#	enter the directory and delete old md5sum file if it exists
#
cd $2
if [ -f DEBIAN/md5sums ] ; then
	echo "DEBIAN/md5sums found. deleting..."
	rm DEBIAN/md5sums ; 
fi
#
#
#	enter the directory and create md5sum file
echo "generating DEBIAN/md5sum file"
md5sum `find . -type f | awk '/.\// {print substr($0, 3) }'` >DEBIAN/md5sums
#
#	move up to root directory
#
cd ..
#
#	hack directory permissions for woody
# 
echo "updating directory permissions"
find ./$2 -type d | xargs chmod 755
#
#	finally build package
#
echo "building package"
/usr/bin/dpkg-deb --build $2 $1



