#! /bin/sh
#
# urandom	This script saves the random seed between reboots.
#		It is called from the boot, halt and reboot scripts.
#
# Version:	@(#)urandom  1.20  27-Nov-1996  MvS.
#

[ -c /dev/urandom ] || exit 0

case "$1" in
	start)
		if [ "$VERBOSE" != no ]
		then
			echo "Initializing random number generator..."
		fi
		# Load and then save 512 bytes,
		# which is the size of the entropy pool
		if [ -f /var/run/random-seed ]
		then
			cat /var/run/random-seed >/dev/urandom
		fi
		rm -f /var/run/random-seed
		umask 077
		dd if=/dev/urandom of=/var/run/random-seed count=1 \
			>/dev/null 2>&1 || echo "urandom start: failed."
		;;
	stop)
		# Carry a random seed from shut-down to start-up;
		# see documentation in linux/drivers/char/random.c
		if [ "$VERBOSE" != no ]
		then
			echo "Saving random seed..."
		fi
		dd if=/dev/urandom of=/var/run/random-seed count=1 \
			>/dev/null 2>&1 || echo "urandom stop: failed."
		;;
	*)
		echo "Usage: urandom {start|stop}" >&2
		exit 1
		;;
esac

