File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 11[Interface]
2- Address = ${INTERFACE}.${CLIENT_IP_IDX }
2+ Address = ${CLIENT_IP }
33PrivateKey = $(cat /config/${PEER_ID}/privatekey-${PEER_ID})
44ListenPort = 51820
55DNS = ${PEERDNS}
Original file line number Diff line number Diff line change @@ -172,7 +172,6 @@ generate_confs () {
172172`cat /config/templates/server.conf`
173173
174174DUDE"
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}
194204PublicKey = $(cat /config/${PEER_ID}/publickey-${PEER_ID})
195- AllowedIPs = ${INTERFACE}.${CLIENT_IP_IDX }/32
205+ AllowedIPs = ${CLIENT_IP }/32
196206
197207DUDE
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
You can’t perform that action at this time.
0 commit comments