Files
wgmn/git-wg-init
2018-05-16 22:43:33 +02:00

31 lines
700 B
Bash
Executable File

#!/bin/bash
NETWORK=${PWD##*/}
IP_ADDR=$1
LPORT=${2:-$(((RANDOM % 5000) + 5000))}
if [ "$#" -ge 3 ]; then
EIP_ADDR=$3
else
EIP_ADDR=$(curl ipecho.net/plain ; echo)
fi
ip link add dev $NETWORK type wireguard
ip address add dev $NETWORK $IP_ADDR
set -e
mkdir -p .wg
echo $NETWORK > .network_name.wg
(umask 077 && wg genkey > .wg/private.key)
wg set $NETWORK private-key .wg/private.key listen-port $LPORT
(umask 077 && wg showconf $NETWORK > .wg/private.conf)
ME=$(wg pubkey < .wg/private.key)
git init
git config user.name "$ME $NETWORK"
git config user.email "$ME@$NETWORK.wg"
echo .wg > .gitignore
git add .
git commit -m "init $NETWORK"
git-wg-peer-add $ME $IP_ADDR "$EIP_ADDR:$LPORT"