File: init-system-common

package info (click to toggle)
rng-tools-debian 2.6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 368 kB
  • sloc: ansic: 2,690; sh: 200; makefile: 58
file content (46 lines) | stat: -rw-r--r-- 945 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -* shell-script -*-

readoptions() {
	HRNGDEVICE=
	HRNGSELECT=
	RNGDOPTIONS=
	test -r /etc/default/rng-tools-debian && . /etc/default/rng-tools-debian
	HRNGDEVICE_=
}

hrngselect() {
	test -z "$HRNGSELECT" || printf '%s' "$HRNGSELECT" \
	    >/sys/devices/virtual/misc/hw_random/rng_current
}

finddevice() {
	if test -n "$HRNGDEVICE" && test -c "$HRNGDEVICE"; then
		# use it unseen
		HRNGDEVICE_=
		return 0
	fi
	# list of devices to try/auto-detect
	for x in hw_random hwrandom intel_rng i810_rng hwrng; do
		for y in /dev /dev/misc; do
			test -c "$y/$x" || continue
			if timeout -k 1s 5s \
			    dd if="$y/$x" bs=1 count=1 >/dev/null 2>&1; then
				HRNGDEVICE=$y/$x
				HRNGDEVICE_=auto
				return 0
			fi
			logger -t rng-tools-debian \
			    "found $y/$x but could not use it"
		done
	done
	return 1
}

skipdevice() {
	case $HRNGDEVICE_:$HRNGDEVICE in
	(auto:/dev/hwrng|auto:/dev/misc/hwrng)
		return 0 ;;
	(*)
		return 1 ;;
	esac
}