ungleich-tools/one-time-scripts/fix-vpn-peers.sh

26 lines
588 B
Bash
Raw Normal View History

#!/bin/sh
vpndir=/home/nico/vcs/ungleich-dot-cdist/type/__ungleich_wireguard/files
for i in $(ls -1 viirb*public_key); do
viirb=${i%.public_key};
num=${viirb#viirb};
hex=$(printf "%0.2x" $num);
pubkey=$(cat $i);
network="2a0a:e5c1:3${hex}::/48";
peerfilename=vpn-2a0ae5c1300.ungleich.ch.peer${hex}
peerfile=${vpndir}/${peerfilename}
if [ ! -f "${peerfile}" ]; then
echo "VIIRB $num / peer $hex missing, recreating"
cat <<EOF > "${peerfile}"
# viirb${num}, $(date +%F)
[Peer]
PublicKey = $pubkey
AllowedIPs = ${network}
EOF
fi
done