#!/bin/sh
#
# use this in place of shutdown if you use root encryption
# it will allow you to select which discs to checksum
#

if [ "$1" = "" ]; then
	echo "Usage: ppdddown your-usual-down-command"
	echo "e.g.   ppdddown reboot"
	exit 1
fi

REPLY=1
if [ -f /sbin/ppddmchk ]
then
	if [ -f /initrd/csum ]
	then
		ppddmchk / /dev/ppdd0
		REPLY=$?
	fi
fi
if [ $REPLY = 0 ]; then
	rm -rf /initrd/check
	mkdir /initrd/check
	mkdir /initrd/check/dev
	LIST=`mount | sort | awk '/ppdd/ { ORS = " "; print $1 }'`
	for LINE in $LIST
	do
	    INTAB=`grep $LINE /etc/ppddtab|cut -d" " -f1`
	    if [ "$LINE" = "/dev/ppdd0" -o "$INTAB" = "y" -o "$INTAB" = "Y" ]
	    then
		OK=0
		while [ $OK = 0 ]
		do
			echo -n "Generate checksum for $LINE (Y/N) ? "
			read REPLY
			if [ "$REPLY" = "Y" ]; then OK=1; fi
			if [ "$REPLY" = "y" ]; then OK=1; fi
			if [ "$REPLY" = "N" ]; then OK=2; fi
			if [ "$REPLY" = "n" ]; then OK=2; fi
		done
		if [ $OK = 1 ]; then
			touch /initrd/check$LINE
		fi
	    fi
	done
fi
# now do it
$*
