S20urandom 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #! /bin/sh
  2. #
  3. # urandom This script saves the random seed between reboots.
  4. # It is called from the boot, halt and reboot scripts.
  5. #
  6. # Version: @(#)urandom 1.33 22-Jun-1998 miquels@cistron.nl
  7. #
  8. [ -c /dev/urandom ] || exit 0
  9. #. /etc/default/rcS
  10. case "$1" in
  11. start|"")
  12. # check for read only file system
  13. if ! touch /etc/random-seed 2>/dev/null
  14. then
  15. # echo "read-only file system detected...done"
  16. exit
  17. fi
  18. if [ "$VERBOSE" != no ]
  19. then
  20. echo -n "Starting random number generator: "
  21. fi
  22. # Load and then save 512 bytes,
  23. # which is the size of the entropy pool
  24. cat /etc/random-seed >/dev/urandom
  25. rm -f /etc/random-seed
  26. umask 077
  27. dd if=/dev/urandom of=/etc/random-seed count=1 \
  28. >/dev/null 2>&1 || echo "ERROR"
  29. umask 022
  30. [ "$VERBOSE" != no ] && echo "OK"
  31. ;;
  32. stop)
  33. if ! touch /etc/random-seed 2>/dev/null
  34. then
  35. exit
  36. fi
  37. # Carry a random seed from shut-down to start-up;
  38. # see documentation in linux/drivers/char/random.c
  39. [ "$VERBOSE" != no ] && echo -n "Stopping random number generator: "
  40. umask 077
  41. dd if=/dev/urandom of=/etc/random-seed count=1 \
  42. >/dev/null 2>&1 || echo "ERROR"
  43. [ "$VERBOSE" != no ] && echo "OK"
  44. ;;
  45. *)
  46. echo "Usage: urandom {start|stop}" >&2
  47. exit 1
  48. ;;
  49. esac