MAGICFILE=`file -v |sed -e '{s/[^/]*\([^:]*\).*/\1/p;s/^.*//p;}'`
echo magic file: $MAGICFILE
if test ! -f $MAGICFILE
then
	echo Cant find $MAGICFILE
	echo append bedmagic yourself to the magic file used by the file command
	exit
fi
IDNUM=`id -u`
NEWMAGIC=/tmp/newbedmagic.$$-$IDNUM
OLDMAGIC=/tmp/oldbedmagic.$$-$IDNUM
THISMAGIC=/tmp/thisbedmagic.$$-$IDNUM
file -m bedmagic testmarks.bedm >$NEWMAGIC
file  testmarks.bedm >$OLDMAGIC
THISDIR=`pwd`
if cmp -s $NEWMAGIC $OLDMAGIC
then
	echo Bed magic already added
else
	cd `dirname $MAGICFILE`
	cp $MAGICFILE $MAGICFILE.beforebed
	cat $THISDIR/bedmagic>>magic
	file -C
	cd $THISDIR
	file testmarks.bedm > $THISMAGIC
	if cmp -s $OLDMAGIC $THISMAGIC
then
		mv $MAGICFILE.beforebed $MAGICFILE
		echo appending bedmagic to $MAGICFILE had no effect
		echo restored existing magic file

	else
		echo bedmagic appended to $MAGICFILE   
		echo old magic saved in $MAGICFILE.beforebed
fi
	rm $THISMAGIC
fi
rm $NEWMAGIC $OLDMAGIC
