apt update
apt install wireguard

wg genkey | tee /etc/wireguard/private.key

cat /etc/wireguard/private.key | wg pubkey | tee /etc/wireguard/public.key

echo -e "[Interface]\nPrivateKey = PrivateKeyGoesHere\nAddress = 10.0.1.1\nListenPort = 5180\nSaveConfig = true\nPostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nPostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE\n\n[Peer]\nPublicKey = PublicKeyGoesHere\nAllowedIPs = 10.0.1.0/24" > /etc/wireguard/wg0.conf

PrivateKey=$(cat /etc/wireguard/private.key)
sed -i 's|PrivateKey = PrivateKeyGoesHere|PrivateKey = '"$PrivateKey"'|' /etc/wireguard/wg0.conf

sed -i 's|#net.ipv4.ip_forward=1|net.ipv4.ip_forward=1|' /etc/sysctl.conf

sed -i 's|#net.ipv6.conf.all.forwarding=1|net.ipv6.conf.all.forwarding=1|' /etc/sysctl.conf

sysctl -p

echo "You have to replace the PublicKey for the peer inside /etc/wireguard/wg0.conf\nThen you enable wireguard with systemctl enable --now wg-quick@wg0.conf"