#!/bin/sh -e
if test $# -lt 1; then
echo "eg. $0 /dev/sda"
exit
fi

echon() {
	printf "%s" "$@"
}
yesno()
{
	msg="$1"
	def="$2"
	while true ; do
	echon "$msg"
	read answer
	if [ "$answer" ] ; then
		case "$answer" in
		y|Y|yes|YES)
			return 0
			;;
		n|N|no|NO)
			return 1
			;;
		*)
			echo " "
			echo "Error: Invalid response, expected \"yes\" or \"no\"."
			continue
			;;
		esac
	else
		return $def
	fi
	done
}

printntsig()
{
echo -n "Current Disk identifier(NT Signature): 0x"
hexdump -s 442 -n 2 $1|head -1|cut -d" " -f2|tr -d '\12'
hexdump -s 440 -n 2 $1|head -1|cut -d" " -f2
}

bsig=`hexdump -s 510 -n 2 $1|head -1|cut -d" " -f2|tr -d '\12'`
if test "$bsig" != "aa55"; then
echo "Not a Valid Boot Sector"
exit
fi

printntsig $1
if yesno "Proceed? yes or no [n] " 1 ; then
dd if=/dev/zero bs=1 seek=440 count=4 of=$1 >/dev/null
if test $? -eq 0; then
echo "Done"
printntsig $1
fi
fi
