update the scripts to use templates

This commit is contained in:
aptalca 2020-04-08 10:46:14 -04:00
parent 49701c97df
commit cd1968d191
4 changed files with 20 additions and 17 deletions

View File

@ -253,6 +253,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
## Versions ## Versions
* **08.04.20:** - Update the `add-peer`/`show-peer` scripts to utilize the templates and the `INTERNAL_SUBNET` var (previously missed, oops).
* **05.04.20:** - Add `INTERNAL_SUBNET` variable to prevent subnet clashes. Add templates for server and peer confs. * **05.04.20:** - Add `INTERNAL_SUBNET` variable to prevent subnet clashes. Add templates for server and peer confs.
* **01.04.20:** - Add `show-peer` script and include info on host installed headers. * **01.04.20:** - Add `show-peer` script and include info on host installed headers.
* **31.03.20:** - Initial Release. * **31.03.20:** - Initial Release.

View File

@ -74,6 +74,7 @@ app_setup_block: |
# changelog # changelog
changelogs: changelogs:
- { date: "08.04.20:", desc: "Update the `add-peer`/`show-peer` scripts to utilize the templates and the `INTERNAL_SUBNET` var (previously missed, oops)." }
- { date: "05.04.20:", desc: "Add `INTERNAL_SUBNET` variable to prevent subnet clashes. Add templates for server and peer confs." } - { date: "05.04.20:", desc: "Add `INTERNAL_SUBNET` variable to prevent subnet clashes. Add templates for server and peer confs." }
- { date: "01.04.20:", desc: "Add `show-peer` script and include info on host installed headers." } - { date: "01.04.20:", desc: "Add `show-peer` script and include info on host installed headers." }
- { date: "31.03.20:", desc: "Initial Release." } - { date: "31.03.20:", desc: "Initial Release." }

View File

@ -1,12 +1,20 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bash
if [ ! -f /config/wg0.conf ] || [ -z "$PEERS" ] || [ -z "$SERVERURL" ]; then if [ ! -f /config/wg0.conf ] || [ -z "$PEERS" ]; then
echo "Wireguard is not set up in server mode" echo "Wireguard is not set up in server mode"
exit 0 exit 0
fi fi
INTERNAL_SUBNET=${INTERNAL_SUBNET:-10.13.13.0}
INTERFACE=$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')
if [ -z "$SERVERURL" ] || [ "$SERVERURL" = "auto" ]; then
SERVERURL=$(curl icanhazip.com)
fi
SERVERPORT=${SERVERPORT:-51820}
PEERDNS=${PEERDNS:-8.8.8.8}
for i in {1..254}; do for i in {1..254}; do
if grep -q "AllowedIPs = 10.13.13.$(( $i + 1 ))/32" /config/wg0.conf; then if grep -q "AllowedIPs = ${INTERFACE}.$(( $i + 1 ))/32" /config/wg0.conf; then
echo "Peer $i exists" echo "Peer $i exists"
else else
echo "Adding new Peer $i" echo "Adding new Peer $i"
@ -15,24 +23,14 @@ for i in {1..254}; do
umask 077 umask 077
wg genkey | tee /config/peer${i}/privatekey-peer${i} | wg pubkey > /config/peer${i}/publickey-peer${i} wg genkey | tee /config/peer${i}/privatekey-peer${i} | wg pubkey > /config/peer${i}/publickey-peer${i}
fi fi
SERVERPORT=${SERVERPORT:-51820} eval "`printf %s`
PEERDNS=${PEERDNS:-8.8.8.8}
cat <<DUDE > /config/peer${i}/peer${i}.conf cat <<DUDE > /config/peer${i}/peer${i}.conf
[Interface] `cat /config/templates/peer.conf`
Address = 10.13.13.$(( $i + 1 )) DUDE"
PrivateKey = $(cat /config/peer${i}/privatekey-peer${i})
ListenPort = 51820
DNS = ${PEERDNS}
[Peer]
PublicKey = $(cat /config/server/publickey-server)
Endpoint = ${SERVERURL}:${SERVERPORT}
AllowedIPs = 0.0.0.0/0, ::/0
DUDE
cat <<DUDE >> /config/wg0.conf cat <<DUDE >> /config/wg0.conf
[Peer] [Peer]
PublicKey = $(cat /config/peer${i}/publickey-peer${i}) PublicKey = $(cat /config/peer${i}/publickey-peer${i})
AllowedIPs = 10.13.13.$(( $i + 1 ))/32 AllowedIPs = ${INTERFACE}.$(( $i + 1 ))/32
DUDE DUDE
echo "PEER ${i} QR code:" echo "PEER ${i} QR code:"

View File

@ -5,8 +5,11 @@ if [ ! $# -gt 0 ]; then
exit 0 exit 0
fi fi
INTERNAL_SUBNET=${INTERNAL_SUBNET:-10.13.13.0}
INTERFACE=$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')
for i in "$@"; do for i in "$@"; do
if grep -q "AllowedIPs = 10.13.13.$(( $i + 1 ))/32" /config/wg0.conf; then if grep -q "AllowedIPs = ${INTERFACE}.$(( $i + 1 ))/32" /config/wg0.conf; then
echo "PEER $i QR code:" echo "PEER $i QR code:"
qrencode -t ansiutf8 < /config/peer${i}/peer${i}.conf qrencode -t ansiutf8 < /config/peer${i}/peer${i}.conf
else else