Skip to content

Instantly share code, notes, and snippets.

@cernoel
Created November 6, 2022 21:34
Show Gist options
  • Save cernoel/f00e404b2544f8daec7b7e8bfbad5805 to your computer and use it in GitHub Desktop.
Save cernoel/f00e404b2544f8daec7b7e8bfbad5805 to your computer and use it in GitHub Desktop.
wg-meshconf bash array mesh configger
#!/bin/bash
# requirements:
# * ssh root access to servers
# * wireguard tools installed
# * https://github.com/k4yt3x/wg-meshconf .. installed on your config machine
declare -a Servers=("ora-fra-one" "ora-fra-two" "ora-fra-three" "ora-ams-one" "ora-ams-two")
counter=101
net=16
# cleanup
rm database.csv
rm -rf output
# create config
for server in ${Servers[@]}; do
echo "ctr: $counter"
wg-meshconf addpeer $server --address 10.$counter.0.1/$net --endpoint $server --persistentkeepalive 10 --mtu 1420
counter=$(( counter + 1 ))
done
wg-meshconf genconfig
# deploy
for server in ${Servers[@]}; do
scp output/$server.conf root@$server:/etc/wireguard/wg0.conf
ssh root@$server "systemctl enable wg-quick@wg0"
ssh root@$server "systemctl restart wg-quick@wg0"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment