Skip to content

Commit 07002a9

Browse files
committed
Fix CLIENT_IP not being set properly when array is modified
1 parent 0ed3fb6 commit 07002a9

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

root/defaults/peer.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[Interface]
2-
Address = ${INTERFACE}.${CLIENT_IP_IDX}
2+
Address = ${CLIENT_IP}
33
PrivateKey = $(cat /config/${PEER_ID}/privatekey-${PEER_ID})
44
ListenPort = 51820
55
DNS = ${PEERDNS}

root/etc/cont-init.d/30-config

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ generate_confs () {
172172
`cat /config/templates/server.conf`
173173

174174
DUDE"
175-
CLIENT_IP_IDX=2
176175
for i in ${PEERS_ARRAY[@]}; do
177176
if [[ "${i}" =~ ^[0-9]+$ ]]; then
178177
PEER_ID="peer${i}"
@@ -184,6 +183,17 @@ DUDE"
184183
umask 077
185184
wg genkey | tee /config/${PEER_ID}/privatekey-${PEER_ID} | wg pubkey > /config/${PEER_ID}/publickey-${PEER_ID}
186185
fi
186+
if [ -f "/config/${PEER_ID}/${PEER_ID}.conf" ]; then
187+
CLIENT_IP=$(cat /config/${PEER_ID}/${PEER_ID}.conf | grep "Address" | awk '{print $NF}')
188+
else
189+
for idx in {2..254}; do
190+
PROPOSED_IP="${INTERFACE}.${idx}"
191+
if ! grep -q -R "${PROPOSED_IP}" /config/peer*/*.conf; then
192+
CLIENT_IP="${PROPOSED_IP}"
193+
break
194+
fi
195+
done
196+
fi
187197
eval "`printf %s`
188198
cat <<DUDE > /config/${PEER_ID}/${PEER_ID}.conf
189199
`cat /config/templates/peer.conf`
@@ -192,10 +202,9 @@ DUDE"
192202
[Peer]
193203
# ${PEER_ID}
194204
PublicKey = $(cat /config/${PEER_ID}/publickey-${PEER_ID})
195-
AllowedIPs = ${INTERFACE}.${CLIENT_IP_IDX}/32
205+
AllowedIPs = ${CLIENT_IP}/32
196206

197207
DUDE
198-
CLIENT_IP_IDX=$(( $CLIENT_IP_IDX + 1 ))
199208
echo "PEER ${i} QR code:"
200209
qrencode -t ansiutf8 < /config/${PEER_ID}/${PEER_ID}.conf
201210
qrencode -o /config/${PEER_ID}/${PEER_ID}.png < /config/${PEER_ID}/${PEER_ID}.conf

0 commit comments

Comments
 (0)