forked from r-pufky/wireguard-initramfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks
executable file
·57 lines (45 loc) · 1.37 KB
/
hooks
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
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
PREREQ=""
prereqs() {
echo "${PREREQ}"
}
case "${1}" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
CONFIG='/etc/wireguard-initramfs/config'
# Validate and copy configuration to initramfs
if [ ! -s "${CONFIG}" ]; then
echo "Wireguard initramfs config required. Missing: ${CONFIG}"
return 1
fi
# shellcheck source=/etc/wireguard-initramfs/config
. "${CONFIG}"
if [ ! -s "${CLIENT_PRIVATE_KEYFILE}" ]; then
echo "Wireguard client private key required. Missing: ${CLIENT_PRIVATE_KEYFILE}"
return 1
fi
if [ -n "${PRE_SHARED_KEY}" ] && [ ! -s "${PRE_SHARED_KEY}" ]; then
echo "Wireguard client pre shared key required. Missing: ${PRE_SHARED_KEY}"
return 1
fi
# Copy latest versions of shared objects needed for DNS resolution
for so in $(ldconfig -p | sed -nr 's/^\s*libnss_files\.so\.[0-9]+\s.*=>\s*//p'); do
copy_exec "${so}"
done
for so in $(ldconfig -p | sed -nr 's/^\s*libnss_dns\.so\.[0-9]+\s.*=>\s*//p'); do
copy_exec "${so}"
done
# Copy config and host keys
mkdir -p -- "${DESTDIR}/etc/wireguard"
cp -p "${CONFIG}" "${DESTDIR}/etc/wireguard"
cp -p "${CLIENT_PRIVATE_KEYFILE}" "${DESTDIR}/etc/wireguard/private_key"
if [ -n "${PRE_SHARED_KEY}" ]; then
cp -p "${PRE_SHARED_KEY}" "${DESTDIR}/etc/wireguard/pre_shared_key"
fi
# Add modules and wireguard exec
manual_add_modules wireguard
copy_exec /usr/bin/wg /sbin