Skip to content

Commit 77567b0

Browse files
committed
Cleanup codebase for release.
Resolve additional bugs found during testing. All x64 tests pass (Pi hardware not available). Added: * Test validating last release (2023-10-21) migrates correctly to current head. Changed: * Cleaned up and standardized strings, variables, comments. * Update log_* messages to confirm to recommended 60 characters or less while still informing what is going on. * init-premount - check wg-quick dependencies before attempting to bring up interface. * migrate_project_structure.sh * Update migration script for current head with logging to inform end user of new configuration location. * set ListenPort to default value; PEER_PORT was implemented but never in a released version; ignore. * Set PersistentKeepalive during migration. * Use script directory detection to correctly source config location regardless of execution directory. * README.md - updated migration instructions.
1 parent b8ae2ac commit 77567b0

13 files changed

Lines changed: 169 additions & 191 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,20 @@ wireguard first. Then restrict to the wireguard network once it is working:
9393
DROPBEAR_OPTIONS='... -p 172.31.255.10:22 ...'
9494
```
9595

96-
## Legacy compatibility
96+
## Legacy compatibility (Migration)
9797

9898
If you are a user using a previous release, such as the one dated
99-
2023-10-21, you can update your current projects by running
99+
2023-10-21, you can update your current projects by running:
100100

101101
```bash
102102
sudo bash scripts/migrate_project_structure.sh
103+
make install
104+
make build_initramfs
103105
```
104106

107+
Adapter configuration is located in `/etc/wireguard/initramfs.conf` and
108+
initramfs configuration is located in `/etc/wireguard/initramfs`.
109+
105110
This should keep your project structure and contents intact; however manual
106111
**validation** is required as full wireguard adapter configs are now supported.
107112

TESTING.md

Lines changed: 0 additions & 80 deletions
This file was deleted.

configs/initramfs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
# Absolute path to working wireguard adapter config for initramfs. This is
2323
# copied to initramfs and loaded after the hardware device is initialized to
2424
# complete wireguard configuration.
25+
#
26+
# PersistentKeepalive is usually required so the machine checks in with the
27+
# wireguard endpoint while booting. If there are issues with no connectivity
28+
# but the adapter config works fine when the system is fully booted, this is
29+
# very likely the cause. Suggest 25 seconds:
30+
#
31+
# PersistentKeepalive = 25
32+
#
2533
ADAPTER=/etc/wireguard/initramfs.conf
2634

2735
# Enable wg-quick for adapter management?

initramfs/hooks

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ esac
2828

2929
. /usr/share/initramfs-tools/hook-functions
3030

31-
WG_INIT_CONFIG="/etc/wireguard/initramfs"
31+
WG_INIT_CONFIG='/etc/wireguard/initramfs'
3232

33-
if [ ! -s "$WG_INIT_CONFIG" ]; then
34-
echo "Wireguard initramfs config required. Missing: $WG_INIT_CONFIG"
33+
if [ ! -s "${WG_INIT_CONFIG}" ]; then
34+
echo "Wireguard initramfs config required. Missing: ${WG_INIT_CONFIG}"
3535
return 1
3636
fi
37-
. "$WG_INIT_CONFIG"
37+
. "${WG_INIT_CONFIG}"
3838

3939
if [ ! -s "${ADAPTER}" ]; then
4040
echo "Wireguard adapter config not found. Missing: ${ADAPTER}"
4141
exit 1
4242
fi
4343
if [ -z "${DATETIME_URL}" ]; then
44-
echo "DATETIME_URL not set (may cause issues for Raspberry Pi devices)."
44+
echo 'DATETIME_URL not set (may cause issues for Raspberry Pi devices).'
4545
fi
4646

4747
# Parse interface section and sanity check.
@@ -116,8 +116,8 @@ fi
116116
cat > "${DESTDIR}/etc/wireguard/initramfs" <<EOL
117117
ADAPTER="${ADAPTER}"
118118
DATETIME_URL="${DATETIME_URL}"
119-
ENABLE_QUICK=${ENABLE_QUICK}
120-
PERSISTENT=${PERSISTENT}
119+
ENABLE_QUICK="${ENABLE_QUICK}"
120+
PERSISTENT="${PERSISTENT}"
121121
INTERFACE="${WG_INTERFACE_NAME}"
122122
INTERFACE_MTU=${WG_INTERFACE_MTU}
123123
INTERFACE_ADDR_IPV4="$(echo "${INTERFACE_ADDR_IPV4}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
@@ -129,11 +129,11 @@ EOL
129129
if [ -n "${DEBUG}" ]; then
130130
echo "${DESTDIR}${ADAPTER}"
131131
cat "${DESTDIR}${ADAPTER}"
132-
echo "-----"
132+
echo '---'
133133
echo "${DESTDIR}/etc/wireguard/initramfs"
134134
cat "${DESTDIR}/etc/wireguard/initramfs"
135135
fi
136136

137-
# Add modules and wireguard exec
137+
# Required wireguard dependencies.
138138
manual_add_modules wireguard
139139
copy_exec /usr/bin/wg /sbin

initramfs/init-premount

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ esac
1616
. /scripts/functions
1717

1818
translate_month() {
19-
case "$1" in
19+
case "${1}" in
2020
Jan) month_number=01 ;;
2121
Feb) month_number=02 ;;
2222
Mar) month_number=03 ;;
@@ -35,11 +35,11 @@ translate_month() {
3535
}
3636

3737
convert_web_date() {
38-
year=$(echo "$1" | cut -d' ' -f 4)
39-
month=$(echo "$1" | cut -d' ' -f 3)
40-
day=$(echo "$1" | cut -d' ' -f 2)
38+
year=$(echo "${1}" | cut -d' ' -f 4)
39+
month=$(echo "${1}" | cut -d' ' -f 3)
40+
day=$(echo "${1}" | cut -d' ' -f 2)
4141

42-
datetime=$(echo "$1" | cut -d' ' -f 5)
42+
datetime=$(echo "${1}" | cut -d' ' -f 5)
4343
hour=$(echo "${datetime}" | cut -d':' -f 1)
4444
minutes=$(echo "${datetime}" | cut -d':' -f 2)
4545
seconds=$(echo "${datetime}" | cut -d':' -f 3)
@@ -50,11 +50,11 @@ convert_web_date() {
5050
}
5151

5252
convert_web_date_compare() {
53-
year=$(echo "$1" | cut -d' ' -f 4)
54-
month=$(echo "$1" | cut -d' ' -f 3)
55-
day=$(echo "$1" | cut -d' ' -f 2)
53+
year=$(echo "${1}" | cut -d' ' -f 4)
54+
month=$(echo "${1}" | cut -d' ' -f 3)
55+
day=$(echo "${1}" | cut -d' ' -f 2)
5656

57-
datetime=$(echo "$1" | cut -d' ' -f 5)
57+
datetime=$(echo "${1}" | cut -d' ' -f 5)
5858
hour=$(echo "${datetime}" | cut -d':' -f 1)
5959
minutes=$(echo "${datetime}" | cut -d':' -f 2)
6060
seconds=$(echo "${datetime}" | cut -d':' -f 3)
@@ -86,14 +86,14 @@ generate_resolv_conf() {
8686
done
8787
}
8888

89-
log_begin_msg 'Check dependencies'
89+
log_begin_msg 'Check required dependencies'
9090
if [ ! -e /sbin/wg ]; then
91-
log_failure_msg 'Wireguard binary (/sbin/wg) not found; skipping start'
91+
log_failure_msg '/sbin/wg: not found; skipping start'
9292
exit 0
9393
fi
9494

9595
if [ ! -e /etc/wireguard/initramfs ]; then
96-
log_failure_msg 'Wireguard config (/etc/wireguard/initramfs) not found; skipping start'
96+
log_failure_msg '/etc/wireguard/initramfs: not found; skipping start'
9797
exit 0
9898
fi
9999
log_end_msg
@@ -109,13 +109,26 @@ log_end_msg
109109

110110
log_begin_msg 'Loading wireguard config'
111111
. /etc/wireguard/initramfs
112+
log_end_msg
113+
114+
log_begin_msg 'Check wg-quick dependencies'
115+
if [ -n "${ENABLE_QUICK}" ] && [ ! -e /sbin/wg-quick ]; then
116+
log_failure_msg '/sbin/wg-quick: not found; skipping start'
117+
exit 0
118+
fi
119+
120+
if [ -n "${ENABLE_QUICK}" ] && [ ! -e /usr/bin/bash ]; then
121+
log_failure_msg '/usr/bin/bash: not found; skipping start'
122+
exit 0
123+
fi
124+
log_end_msg
112125

126+
log_begin_msg 'Final sanity check to prevent boot wedging'
113127
if [ ! -e "${ADAPTER}" ]; then
114-
log_failure_msg "Wireguard adapter config (${ADAPTER}) not found; skipping start"
128+
log_failure_msg "${ADAPTER}: not found; skipping start"
115129
exit 0
116130
fi
117131

118-
# Final sanity check to prevent boot wedging.
119132
if [ -z "${INTERFACE}" ]; then
120133
log_failure_msg 'Interface name is not defined'
121134
return 1
@@ -133,7 +146,7 @@ fi
133146
log_end_msg
134147

135148
if [ -n "${DATETIME_URL}" ]; then
136-
log_begin_msg 'set local date time'
149+
log_begin_msg 'Set local date time'
137150
date_from_web=$(wget -qSO- "${DATETIME_URL}" 2>&1 | sed -n 's/^ *Date: *//p' | head -n 1)
138151

139152
date_web_comp=$(date -d "$(convert_web_date_compare "${date_from_web}")" +%s)
@@ -145,12 +158,12 @@ if [ -n "${DATETIME_URL}" ]; then
145158
log_warning_msg "set date to: ${date_to_set}"
146159
date -s "${date_to_set}" > /dev/null
147160
else
148-
log_success_msg "no need to set new date"
161+
log_success_msg "No need to set new date"
149162
fi
150163
log_end_msg
151164
fi
152165

153-
log_begin_msg 'Initialize and starting wireguard'
166+
log_begin_msg 'Initialize and start wireguard'
154167
if [ -n "${ENABLE_QUICK}" ]; then
155168
wg-quick up "${ADAPTER}"
156169
else

scripts/build_wg_setconf.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@ else
1111
CONFIG_PATH="${CONFIG}"
1212
fi
1313

14-
# shellcheck source="${CONFIG_PATH}/initramfs" - load variables.
15-
WG_CONFIG="${CONFIG_PATH}/initramfs"
16-
source "${WG_CONFIG}"
14+
WG_INIT_CONFIG="${CONFIG_PATH}/initramfs"
15+
. "${WG_INIT_CONFIG}"
1716

1817
if [ ! -s "${ADAPTER}" ]; then
1918
echo "Wireguard adapter config not found. Missing: ${ADAPTER}"
2019
exit 1
2120
fi
22-
2321
if [ -z "${DATETIME_URL}" ]; then
2422
echo "DATETIME_URL not set (may cause issues for Raspberry Pi devices)."
2523
fi
2624

27-
cp "${WG_CONFIG}" "/etc/wireguard/initramfs"
25+
cp "${WG_INIT_CONFIG}" "/etc/wireguard/initramfs"
2826

2927
exit 0

0 commit comments

Comments
 (0)