base-files: seed /dev/urandom
[openwrt/staging/lynxis/omap.git] / package / base-files / files / lib / preinit / 81_urandom_seed
1 #!/bin/sh
2
3 log_urandom_seed() {
4 echo "urandom-seed: $1" > /dev/kmsg
5 }
6
7 _do_urandom_seed() {
8 [ -f "$1" ] || { log_urandom_seed "Seed file not found ($1)"; return; }
9 [ -O "$1" -a -G "$1" -a ! -x "$1" ] || { log_urandom_seed "Wrong owner / permissions for $1"; return; }
10
11 log_urandom_seed "Seeding with $1"
12 cat "$1" > /dev/urandom
13 }
14
15 do_urandom_seed() {
16 [ -c /dev/urandom ] || { log_urandom_seed "Something is wrong with /dev/urandom"; return; }
17
18 _do_urandom_seed "/etc/urandom.seed"
19
20 SEED="$(uci -q get system.@system[0].urandom_seed)"
21 [ "${SEED:0:1}" == "/" -a "$SEED" != "/etc/urandom.seed" ] && _do_urandom_seed "$SEED"
22 }
23
24 boot_hook_add preinit_main do_urandom_seed