diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-09 17:15:40 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-09 17:20:10 +1200 |
commit | 9fb350dc7c8cc5259ef24e0cb097031179fab1d6 (patch) | |
tree | 839dd0b8ee3f5323b1cd6aefa22b605b99437d62 /bin/rnds | |
parent | Mention nosls/sls flags in slsf(1) man page (diff) | |
download | dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.tar.gz dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.zip |
Improve commenting/exit handling in binscripts
Diffstat (limited to 'bin/rnds')
-rwxr-xr-x | bin/rnds | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -1,11 +1,22 @@ #!/bin/sh # Try to get a low-quality random seed from a random device if possible -[ "$#" -le 1 ] || exit 2 + +# Sole optional argument is the bytes to read; 32 is the default +count=${1:-32} + +# Try and find a random device to use; none of these are specified by POSIX for dev in /dev/urandom /dev/arandom /dev/random '' ; do [ -e "$dev" ] && break done + +# Bail if we couldn't find a random device [ -n "$dev" ] || exit 1 -count=${1:-32} + +# Read the bytes from the device dd if="$dev" bs=1 count="$count" 2>/dev/null | + +# Run cksum(1) over the read random bytes cksum | + +# cut(1) the cksum(1) output to only the first field, and print that to stdout cut -d' ' -f1 |