Created
November 8, 2021 13:50
-
-
Save mdrokz/2262f6db05c11350be8436c48bd42868 to your computer and use it in GitHub Desktop.
Fish functions to generate & add wireguard client config file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generate_wg_client | |
mkdir /home/mdrokz/wireguard/$argv[1] | |
cd /home/mdrokz/wireguard/$argv[1] | |
umask 077 | |
touch $argv[1].conf | |
wg genkey > $argv[1].key | |
wg pubkey < $argv[1].key > $argv[1].pub | |
wg genpsk > $argv[1].psk | |
echo "[Interface]" >> $argv[1].conf | |
echo "Address = $argv[2]/32" >> $argv[1].conf | |
echo "PrivateKey = " (cat $argv[1].key) >> $argv[1].conf | |
echo "\n" >> $argv[1].conf | |
echo "[Peer]" >> $argv[1].conf | |
echo "Endpoint = $argv[3]:49312" >> $argv[1].conf | |
echo "AllowedIPs = 10.254.0.0/24" >> $argv[1].conf | |
echo "PublicKey = " (sudo cat /etc/wireguard/server.pub) >> $argv[1].conf | |
echo "PresharedKey = " (cat $argv[1].psk) >> $argv[1].conf | |
end | |
function add_wg_client | |
cd /home/mdrokz/wireguard/server/ | |
echo "[Peer]" >> wg0.conf | |
echo "PublicKey =" (cat /home/mdrokz/wireguard/$argv[1]/$argv[1].pub) >> wg0.conf | |
echo "PresharedKey =" (cat /home/mdrokz/wireguard/$argv[1]/$argv[1].psk) >> wg0.conf | |
echo "AllowedIPs = $argv[2]/32" >> wg0.conf | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment