S20urandom 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. if [ "$VERBOSE" != no ]
  13. then
  14. echo -n "Initializing random number generator... "
  15. fi
  16. # Load and then save 512 bytes,
  17. # which is the size of the entropy pool
  18. if [ -f /etc/random-seed ]
  19. then
  20. cat /etc/random-seed >/dev/urandom
  21. fi
  22. # check for read only file system
  23. if ! touch /etc/random-seed 2>/dev/null
  24. then
  25. echo "read-only file system detected...done"
  26. exit
  27. fi
  28. rm -f /etc/random-seed
  29. umask 077
  30. dd if=/dev/urandom of=/etc/random-seed count=1 \
  31. >/dev/null 2>&1 || echo "urandom start: failed."
  32. umask 022
  33. [ "$VERBOSE" != no ] && echo "done."
  34. ;;
  35. stop)
  36. if ! touch /etc/random-seed 2>/dev/null
  37. then
  38. exit
  39. fi
  40. # Carry a random seed from shut-down to start-up;
  41. # see documentation in linux/drivers/char/random.c
  42. [ "$VERBOSE" != no ] && echo -n "Saving random seed... "
  43. umask 077
  44. dd if=/dev/urandom of=/etc/random-seed count=1 \
  45. >/dev/null 2>&1 || echo "urandom stop: failed."
  46. [ "$VERBOSE" != no ] && echo "done."
  47. ;;
  48. *)
  49. echo "Usage: urandom {start|stop}" >&2
  50. exit 1
  51. ;;
  52. esac