#!/bin/bash

## gensum.sh v1.03 (17th December 2012) by Andy Davison
##  Generates appropriate checksum files for USB installers.

if [ $# -ne 3 ]; then
	echo "Usage: $0 <keyfile> <payload> <output>"
	exit 1
else
	MD5=`md5sum $2 | sed -e 's/  .*//'`
	echo "Genuine checksum of the payload '$2' is '$MD5'..."
	SUM=`cat $2 $1 | md5sum | sed -e 's/  .*//'`
	echo -n $SUM > $3/.sum
	echo -n $MD5 > $3/.usb-sum
	echo
	echo "Checksum '$SUM' has been written to '$3/.sum' for v26635 (O2)."
	echo "Checksum '$MD5' has been written to '$3/.usb-key' for v30300 (OP)."
	exit 0
fi
