Skip to content

Commit 095f857

Browse files
authored
Merge pull request #341 from linuxserver/master-ro-tweaks
Update readme, lint whitespace
2 parents 819d7cb + 930bd7e commit 095f857

File tree

2 files changed

+81
-79
lines changed

2 files changed

+81
-79
lines changed

readme-vars.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ opt_param_env_vars:
5454
- { env_var: "PERSISTENTKEEPALIVE_PEERS", env_value: "", desc: "Set to `all` or a list of comma separated peers (ie. `1,4,laptop`) for the wireguard server to send keepalive packets to listed peers every 25 seconds. Useful if server is accessed via domain name and has dynamic IP. Used only in server mode."}
5555
- { env_var: "LOG_CONFS", env_value: "true", desc: "Generated QR codes will be displayed in the docker log. Set to `false` to skip log output."}
5656

57-
optional_block_1: false
58-
optional_block_1_items: ""
57+
readonly_supported: true
58+
readonly_message: |
59+
* Not supported in client mode.
60+
* Not supported for the `legacy` tag.
5961
6062
# application setup block
6163
app_setup_block_enabled: true

root/etc/s6-overlay/s6-rc.d/init-wireguard-confs/run

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -34,94 +34,94 @@ generate_confs () {
3434
$(cat /config/templates/server.conf)
3535

3636
DUDE"
37-
for i in "${PEERS_ARRAY[@]}"; do
38-
if [[ ! "${i}" =~ ^[[:alnum:]]+$ ]]; then
39-
echo "**** Peer ${i} contains non-alphanumeric characters and thus will be skipped. No config for peer ${i} will be generated. ****"
40-
else
41-
if [[ "${i}" =~ ^[0-9]+$ ]]; then
42-
PEER_ID="peer${i}"
43-
else
44-
PEER_ID="peer_${i}"
45-
fi
46-
mkdir -p "/config/${PEER_ID}"
47-
if [[ ! -f "/config/${PEER_ID}/privatekey-${PEER_ID}" ]]; then
48-
umask 077
49-
wg genkey | tee "/config/${PEER_ID}/privatekey-${PEER_ID}" | wg pubkey > "/config/${PEER_ID}/publickey-${PEER_ID}"
50-
wg genpsk > "/config/${PEER_ID}/presharedkey-${PEER_ID}"
51-
fi
52-
if [[ -f "/config/${PEER_ID}/${PEER_ID}.conf" ]]; then
53-
CLIENT_IP=$(grep "Address" "/config/${PEER_ID}/${PEER_ID}.conf" | awk '{print $NF}')
54-
if [[ -n "${ORIG_INTERFACE}" ]] && [[ "${INTERFACE}" != "${ORIG_INTERFACE}" ]]; then
55-
CLIENT_IP="${CLIENT_IP//${ORIG_INTERFACE}/${INTERFACE}}"
56-
fi
57-
else
58-
for idx in {2..254}; do
59-
PROPOSED_IP="${INTERFACE}.${idx}"
60-
if ! grep -q -R "${PROPOSED_IP}" /config/peer*/*.conf 2>/dev/null && ([[ -z "${ORIG_INTERFACE}" ]] || ! grep -q -R "${ORIG_INTERFACE}.${idx}" /config/peer*/*.conf 2>/dev/null); then
61-
CLIENT_IP="${PROPOSED_IP}"
62-
break
63-
fi
64-
done
65-
fi
66-
if [[ -f "/config/${PEER_ID}/presharedkey-${PEER_ID}" ]]; then
67-
# create peer conf with presharedkey
68-
eval "$(printf %s)
69-
cat <<DUDE > /config/${PEER_ID}/${PEER_ID}.conf
37+
for i in "${PEERS_ARRAY[@]}"; do
38+
if [[ ! "${i}" =~ ^[[:alnum:]]+$ ]]; then
39+
echo "**** Peer ${i} contains non-alphanumeric characters and thus will be skipped. No config for peer ${i} will be generated. ****"
40+
else
41+
if [[ "${i}" =~ ^[0-9]+$ ]]; then
42+
PEER_ID="peer${i}"
43+
else
44+
PEER_ID="peer_${i}"
45+
fi
46+
mkdir -p "/config/${PEER_ID}"
47+
if [[ ! -f "/config/${PEER_ID}/privatekey-${PEER_ID}" ]]; then
48+
umask 077
49+
wg genkey | tee "/config/${PEER_ID}/privatekey-${PEER_ID}" | wg pubkey > "/config/${PEER_ID}/publickey-${PEER_ID}"
50+
wg genpsk > "/config/${PEER_ID}/presharedkey-${PEER_ID}"
51+
fi
52+
if [[ -f "/config/${PEER_ID}/${PEER_ID}.conf" ]]; then
53+
CLIENT_IP=$(grep "Address" "/config/${PEER_ID}/${PEER_ID}.conf" | awk '{print $NF}')
54+
if [[ -n "${ORIG_INTERFACE}" ]] && [[ "${INTERFACE}" != "${ORIG_INTERFACE}" ]]; then
55+
CLIENT_IP="${CLIENT_IP//${ORIG_INTERFACE}/${INTERFACE}}"
56+
fi
57+
else
58+
for idx in {2..254}; do
59+
PROPOSED_IP="${INTERFACE}.${idx}"
60+
if ! grep -q -R "${PROPOSED_IP}" /config/peer*/*.conf 2>/dev/null && ([[ -z "${ORIG_INTERFACE}" ]] || ! grep -q -R "${ORIG_INTERFACE}.${idx}" /config/peer*/*.conf 2>/dev/null); then
61+
CLIENT_IP="${PROPOSED_IP}"
62+
break
63+
fi
64+
done
65+
fi
66+
if [[ -f "/config/${PEER_ID}/presharedkey-${PEER_ID}" ]]; then
67+
# create peer conf with presharedkey
68+
eval "$(printf %s)
69+
cat <<DUDE > /config/${PEER_ID}/${PEER_ID}.conf
7070
$(cat /config/templates/peer.conf)
7171
DUDE"
72-
# add peer info to server conf with presharedkey
73-
cat <<DUDE >> /config/wg_confs/wg0.conf
72+
# add peer info to server conf with presharedkey
73+
cat <<DUDE >> /config/wg_confs/wg0.conf
7474
[Peer]
7575
# ${PEER_ID}
7676
PublicKey = $(cat "/config/${PEER_ID}/publickey-${PEER_ID}")
7777
PresharedKey = $(cat "/config/${PEER_ID}/presharedkey-${PEER_ID}")
7878
DUDE
79-
else
80-
echo "**** Existing keys with no preshared key found for ${PEER_ID}, creating confs without preshared key for backwards compatibility ****"
81-
# create peer conf without presharedkey
82-
eval "$(printf %s)
83-
cat <<DUDE > /config/${PEER_ID}/${PEER_ID}.conf
79+
else
80+
echo "**** Existing keys with no preshared key found for ${PEER_ID}, creating confs without preshared key for backwards compatibility ****"
81+
# create peer conf without presharedkey
82+
eval "$(printf %s)
83+
cat <<DUDE > /config/${PEER_ID}/${PEER_ID}.conf
8484
$(sed '/PresharedKey/d' "/config/templates/peer.conf")
8585
DUDE"
86-
# add peer info to server conf without presharedkey
87-
cat <<DUDE >> /config/wg_confs/wg0.conf
86+
# add peer info to server conf without presharedkey
87+
cat <<DUDE >> /config/wg_confs/wg0.conf
8888
[Peer]
8989
# ${PEER_ID}
9090
PublicKey = $(cat "/config/${PEER_ID}/publickey-${PEER_ID}")
9191
DUDE
92-
fi
93-
SERVER_ALLOWEDIPS=SERVER_ALLOWEDIPS_PEER_${i}
94-
# add peer's allowedips to server conf
95-
if [[ -n "${!SERVER_ALLOWEDIPS}" ]]; then
96-
echo "Adding ${!SERVER_ALLOWEDIPS} to wg0.conf's AllowedIPs for peer ${i}"
97-
cat <<DUDE >> /config/wg_confs/wg0.conf
92+
fi
93+
SERVER_ALLOWEDIPS=SERVER_ALLOWEDIPS_PEER_${i}
94+
# add peer's allowedips to server conf
95+
if [[ -n "${!SERVER_ALLOWEDIPS}" ]]; then
96+
echo "Adding ${!SERVER_ALLOWEDIPS} to wg0.conf's AllowedIPs for peer ${i}"
97+
cat <<DUDE >> /config/wg_confs/wg0.conf
9898
AllowedIPs = ${CLIENT_IP}/32,${!SERVER_ALLOWEDIPS}
9999
DUDE
100-
else
101-
cat <<DUDE >> /config/wg_confs/wg0.conf
100+
else
101+
cat <<DUDE >> /config/wg_confs/wg0.conf
102102
AllowedIPs = ${CLIENT_IP}/32
103103
DUDE
104-
fi
105-
# add PersistentKeepalive if the peer is specified
106-
if [[ -n "${PERSISTENTKEEPALIVE_PEERS_ARRAY}" ]] && ([[ "${PERSISTENTKEEPALIVE_PEERS_ARRAY[0]}" = "all" ]] || printf '%s\0' "${PERSISTENTKEEPALIVE_PEERS_ARRAY[@]}" | grep -Fxqz -- "${i}"); then
107-
cat <<DUDE >> /config/wg_confs/wg0.conf
104+
fi
105+
# add PersistentKeepalive if the peer is specified
106+
if [[ -n "${PERSISTENTKEEPALIVE_PEERS_ARRAY}" ]] && ([[ "${PERSISTENTKEEPALIVE_PEERS_ARRAY[0]}" = "all" ]] || printf '%s\0' "${PERSISTENTKEEPALIVE_PEERS_ARRAY[@]}" | grep -Fxqz -- "${i}"); then
107+
cat <<DUDE >> /config/wg_confs/wg0.conf
108108
PersistentKeepalive = 25
109109

110110
DUDE
111-
else
112-
cat <<DUDE >> /config/wg_confs/wg0.conf
111+
else
112+
cat <<DUDE >> /config/wg_confs/wg0.conf
113113

114114
DUDE
115-
fi
116-
if [[ -z "${LOG_CONFS}" ]] || [[ "${LOG_CONFS}" = "true" ]]; then
117-
echo "PEER ${i} QR code (conf file is saved under /config/${PEER_ID}):"
118-
qrencode -t ansiutf8 < "/config/${PEER_ID}/${PEER_ID}.conf"
119-
else
120-
echo "PEER ${i} conf and QR code png saved in /config/${PEER_ID}"
121-
fi
122-
qrencode -o "/config/${PEER_ID}/${PEER_ID}.png" < "/config/${PEER_ID}/${PEER_ID}.conf"
123-
fi
124-
done
115+
fi
116+
if [[ -z "${LOG_CONFS}" ]] || [[ "${LOG_CONFS}" = "true" ]]; then
117+
echo "PEER ${i} QR code (conf file is saved under /config/${PEER_ID}):"
118+
qrencode -t ansiutf8 < "/config/${PEER_ID}/${PEER_ID}.conf"
119+
else
120+
echo "PEER ${i} conf and QR code png saved in /config/${PEER_ID}"
121+
fi
122+
qrencode -o "/config/${PEER_ID}/${PEER_ID}.png" < "/config/${PEER_ID}/${PEER_ID}.conf"
123+
fi
124+
done
125125
}
126126

127127
save_vars () {
@@ -171,17 +171,17 @@ if [[ -n "$PEERS" ]]; then
171171
generate_confs
172172
save_vars
173173
else
174-
echo "**** Server mode is selected ****"
175-
if [[ -f /config/.donoteditthisfile ]]; then
176-
. /config/.donoteditthisfile
177-
fi
178-
if [[ "$SERVERURL" != "$ORIG_SERVERURL" ]] || [[ "$SERVERPORT" != "$ORIG_SERVERPORT" ]] || [[ "$PEERDNS" != "$ORIG_PEERDNS" ]] || [[ "$PEERS" != "$ORIG_PEERS" ]] || [[ "$INTERFACE" != "$ORIG_INTERFACE" ]] || [[ "$ALLOWEDIPS" != "$ORIG_ALLOWEDIPS" ]] || [[ "$PERSISTENTKEEPALIVE_PEERS" != "$ORIG_PERSISTENTKEEPALIVE_PEERS" ]]; then
179-
echo "**** Server related environment variables changed, regenerating 1 server and ${PEERS} peer/client confs ****"
180-
generate_confs
181-
save_vars
182-
else
183-
echo "**** No changes to parameters. Existing configs are used. ****"
184-
fi
174+
echo "**** Server mode is selected ****"
175+
if [[ -f /config/.donoteditthisfile ]]; then
176+
. /config/.donoteditthisfile
177+
fi
178+
if [[ "$SERVERURL" != "$ORIG_SERVERURL" ]] || [[ "$SERVERPORT" != "$ORIG_SERVERPORT" ]] || [[ "$PEERDNS" != "$ORIG_PEERDNS" ]] || [[ "$PEERS" != "$ORIG_PEERS" ]] || [[ "$INTERFACE" != "$ORIG_INTERFACE" ]] || [[ "$ALLOWEDIPS" != "$ORIG_ALLOWEDIPS" ]] || [[ "$PERSISTENTKEEPALIVE_PEERS" != "$ORIG_PERSISTENTKEEPALIVE_PEERS" ]]; then
179+
echo "**** Server related environment variables changed, regenerating 1 server and ${PEERS} peer/client confs ****"
180+
generate_confs
181+
save_vars
182+
else
183+
echo "**** No changes to parameters. Existing configs are used. ****"
184+
fi
185185
fi
186186
else
187187
echo "**** Client mode selected. ****"

0 commit comments

Comments
 (0)