Skip to content

Commit cd1968d

Browse files
committed
update the scripts to use templates
1 parent 49701c9 commit cd1968d

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
253253

254254
## Versions
255255

256+
* **08.04.20:** - Update the `add-peer`/`show-peer` scripts to utilize the templates and the `INTERNAL_SUBNET` var (previously missed, oops).
256257
* **05.04.20:** - Add `INTERNAL_SUBNET` variable to prevent subnet clashes. Add templates for server and peer confs.
257258
* **01.04.20:** - Add `show-peer` script and include info on host installed headers.
258259
* **31.03.20:** - Initial Release.

readme-vars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ app_setup_block: |
7474
7575
# changelog
7676
changelogs:
77+
- { date: "08.04.20:", desc: "Update the `add-peer`/`show-peer` scripts to utilize the templates and the `INTERNAL_SUBNET` var (previously missed, oops)." }
7778
- { date: "05.04.20:", desc: "Add `INTERNAL_SUBNET` variable to prevent subnet clashes. Add templates for server and peer confs." }
7879
- { date: "01.04.20:", desc: "Add `show-peer` script and include info on host installed headers." }
7980
- { date: "31.03.20:", desc: "Initial Release." }

root/app/add-peer

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#!/usr/bin/with-contenv bash
22

3-
if [ ! -f /config/wg0.conf ] || [ -z "$PEERS" ] || [ -z "$SERVERURL" ]; then
3+
if [ ! -f /config/wg0.conf ] || [ -z "$PEERS" ]; then
44
echo "Wireguard is not set up in server mode"
55
exit 0
66
fi
77

8+
INTERNAL_SUBNET=${INTERNAL_SUBNET:-10.13.13.0}
9+
INTERFACE=$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')
10+
if [ -z "$SERVERURL" ] || [ "$SERVERURL" = "auto" ]; then
11+
SERVERURL=$(curl icanhazip.com)
12+
fi
13+
SERVERPORT=${SERVERPORT:-51820}
14+
PEERDNS=${PEERDNS:-8.8.8.8}
15+
816
for i in {1..254}; do
9-
if grep -q "AllowedIPs = 10.13.13.$(( $i + 1 ))/32" /config/wg0.conf; then
17+
if grep -q "AllowedIPs = ${INTERFACE}.$(( $i + 1 ))/32" /config/wg0.conf; then
1018
echo "Peer $i exists"
1119
else
1220
echo "Adding new Peer $i"
@@ -15,24 +23,14 @@ for i in {1..254}; do
1523
umask 077
1624
wg genkey | tee /config/peer${i}/privatekey-peer${i} | wg pubkey > /config/peer${i}/publickey-peer${i}
1725
fi
18-
SERVERPORT=${SERVERPORT:-51820}
19-
PEERDNS=${PEERDNS:-8.8.8.8}
26+
eval "`printf %s`
2027
cat <<DUDE > /config/peer${i}/peer${i}.conf
21-
[Interface]
22-
Address = 10.13.13.$(( $i + 1 ))
23-
PrivateKey = $(cat /config/peer${i}/privatekey-peer${i})
24-
ListenPort = 51820
25-
DNS = ${PEERDNS}
26-
27-
[Peer]
28-
PublicKey = $(cat /config/server/publickey-server)
29-
Endpoint = ${SERVERURL}:${SERVERPORT}
30-
AllowedIPs = 0.0.0.0/0, ::/0
31-
DUDE
28+
`cat /config/templates/peer.conf`
29+
DUDE"
3230
cat <<DUDE >> /config/wg0.conf
3331
[Peer]
3432
PublicKey = $(cat /config/peer${i}/publickey-peer${i})
35-
AllowedIPs = 10.13.13.$(( $i + 1 ))/32
33+
AllowedIPs = ${INTERFACE}.$(( $i + 1 ))/32
3634

3735
DUDE
3836
echo "PEER ${i} QR code:"

root/app/show-peer

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ if [ ! $# -gt 0 ]; then
55
exit 0
66
fi
77

8+
INTERNAL_SUBNET=${INTERNAL_SUBNET:-10.13.13.0}
9+
INTERFACE=$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')
10+
811
for i in "$@"; do
9-
if grep -q "AllowedIPs = 10.13.13.$(( $i + 1 ))/32" /config/wg0.conf; then
12+
if grep -q "AllowedIPs = ${INTERFACE}.$(( $i + 1 ))/32" /config/wg0.conf; then
1013
echo "PEER $i QR code:"
1114
qrencode -t ansiutf8 < /config/peer${i}/peer${i}.conf
1215
else

0 commit comments

Comments
 (0)