mirror of
https://github.com/linuxserver/docker-wireguard.git
synced 2026-02-05 03:27:32 +08:00
update the scripts to use templates
This commit is contained in:
parent
49701c97df
commit
cd1968d191
@ -253,6 +253,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
|
||||
|
||||
## 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.
|
||||
* **01.04.20:** - Add `show-peer` script and include info on host installed headers.
|
||||
* **31.03.20:** - Initial Release.
|
||||
|
||||
@ -74,6 +74,7 @@ app_setup_block: |
|
||||
|
||||
# changelog
|
||||
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: "01.04.20:", desc: "Add `show-peer` script and include info on host installed headers." }
|
||||
- { date: "31.03.20:", desc: "Initial Release." }
|
||||
|
||||
@ -1,12 +1,20 @@
|
||||
#!/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"
|
||||
exit 0
|
||||
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
|
||||
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"
|
||||
else
|
||||
echo "Adding new Peer $i"
|
||||
@ -15,24 +23,14 @@ for i in {1..254}; do
|
||||
umask 077
|
||||
wg genkey | tee /config/peer${i}/privatekey-peer${i} | wg pubkey > /config/peer${i}/publickey-peer${i}
|
||||
fi
|
||||
SERVERPORT=${SERVERPORT:-51820}
|
||||
PEERDNS=${PEERDNS:-8.8.8.8}
|
||||
eval "`printf %s`
|
||||
cat <<DUDE > /config/peer${i}/peer${i}.conf
|
||||
[Interface]
|
||||
Address = 10.13.13.$(( $i + 1 ))
|
||||
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 /config/templates/peer.conf`
|
||||
DUDE"
|
||||
cat <<DUDE >> /config/wg0.conf
|
||||
[Peer]
|
||||
PublicKey = $(cat /config/peer${i}/publickey-peer${i})
|
||||
AllowedIPs = 10.13.13.$(( $i + 1 ))/32
|
||||
AllowedIPs = ${INTERFACE}.$(( $i + 1 ))/32
|
||||
|
||||
DUDE
|
||||
echo "PEER ${i} QR code:"
|
||||
|
||||
@ -5,8 +5,11 @@ if [ ! $# -gt 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
INTERNAL_SUBNET=${INTERNAL_SUBNET:-10.13.13.0}
|
||||
INTERFACE=$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')
|
||||
|
||||
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:"
|
||||
qrencode -t ansiutf8 < /config/peer${i}/peer${i}.conf
|
||||
else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user