#!/bin/bash

	eraseManifest="true"
	myDirName=`pwd`
	myDirName=${myDirName##*/}
	myGtDirName=`pwd`
	myGtDirName=${myGtDirName%/*}
	myGtDirName=${myGtDirName##*/}
	myDirName=$myGtDirName"."$myDirName

	if [[ -e wepsrepacktemp ]] ; then
	    echo "Temp dir (wepsrepacktemp) already exists."
	    echo "Please remove it and then continue."
	    exit
	fi

	mynewjar="weps-$myDirName.jar"
	rm $mynewjar
	myjars="*.jar"
	
	mkdir wepsrepacktemp
	cd wepsrepacktemp
	echo working in:`pwd`
	
	# unpack all of the jars in the specified lib dir (and subdirs)
	#find ../lib/$1 -name "*\.jar" -exec echo \{\} mmm \;
	#find . -name "*\.jar" -exec jar xvf \{\} \;
	for i in ../$myjars; do
		echo $i
		jar xvf $i &>/dev/null
	done

	echo buiding $mynewjar
	if [[ "$eraseManifest" == "true" ]] ; then
		echo New empty manifest
		# This dir has been overridden by each unpack, just delete
		# the jar command will create a new one.
		rm -rf META-INF/MANIFEST.MF
		rm -rf META-INF/maven
		rm -rf META-INF/DUMMY*
		# Now put everything back together into a single jar
		jar cvf ../$mynewjar "*"  &>/dev/null
	else
		echo Using the existing manifest
		# Leave the manifest (occasionaly).

		# Now put everything back together into a single jar
		jar cvfm ../$mynewjar META-INF/MANIFEST.MF "*" &>/dev/null
	fi
	
	# clean up and exit
	cd ..
	rm -rf wepsrepacktemp
