summaryrefslogtreecommitdiffstats
path: root/modules.d/haveged/module-setup.sh
blob: 6cd1e1b83944b68380197f8199104041f46695d5 (plain) (blame)
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
#!/bin/bash

check() {
	if ! hash haveged 2>/dev/null; then
		warn "Could not find haveged in $PATH. Check if its installed."
		return 1
	fi
	return 0
}
# called by dracut
install() {
	# see where haveged is installed
	local haveged_bin="$(command -v haveged)"
	if [ -z "$haveged_bin" ]; then
		warn "Could not find havaged in $PATH. Check if its installed."
		return 1
	fi
	# TODO SysVInit support, if that even a thing anymore :)
	local haveged_service="$systemdsystemunitdir/haveged.service"
	if [ ! -f "$haveged_service" ]; then
		# query systemd	directly
		haveged_service="$(systemctl show -p FragmentPath haveged | cut -c 14-)"
		if [ -z "$haveged_service" ]; then
			warn "Could not find haveged service in '$systemdsystemunitdir' or by querying systemd."
			warn "Check if it is installed properly."
			return 1
		fi
	fi
	inst_multiple -o \
		"$haveged_bin" \
		"$haveged_service"

	# In Ubuntu, the service sources an EnvironmentFile for default options
	local haveged_env_file="$(grep -oP '^EnvironmentFile=-?\K.*' $haveged_service)"
	if [ -n "$haveged_env_file" ]; then
		mkdir -p "$initdir/${haveged_env_file%/*}" 2>/dev/null
		cp "$haveged_env_file" "$initdir/$haveged_env_file"
	fi
	mkdir -p "$initdir/$systemdsystemunitdir/basic.target.wants" 2>/dev/null
	ln_r "$systemdsystemunitdir/haveged.service" "$systemdsystemunitdir/basic.target.wants/haveged.service"
}