init commit
This commit is contained in:
30
git-wg-clone
Executable file
30
git-wg-clone
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
URL=$1
|
||||
NETWORK=$(basename "$URL")
|
||||
IP_ADDR=$2
|
||||
LPORT=${3:-$(((RANDOM % 5000) + 5000))}
|
||||
if [ "$#" -ge 4 ]; then
|
||||
EIP_ADDR=$4
|
||||
else
|
||||
EIP_ADDR=$(curl ipecho.net/plain ; echo)
|
||||
fi
|
||||
set -e
|
||||
|
||||
git clone $URL
|
||||
cd "$NETWORK"
|
||||
|
||||
set +e
|
||||
ip link add dev $NETWORK type wireguard
|
||||
ip address add dev $NETWORK $IP_ADDR
|
||||
#set -e
|
||||
|
||||
mkdir -p .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 config user.name "$ME $NETWORK"
|
||||
git config user.email "$ME@$NETWORK.wg"
|
||||
|
||||
git-wg-peer-add $ME $IP_ADDR "$EIP_ADDR:$LPORT"
|
||||
30
git-wg-init
Executable file
30
git-wg-init
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/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"
|
||||
3
git-wg-peer
Executable file
3
git-wg-peer
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
COMMAND=$1
|
||||
git-wg-peer-$COMMAND "${@:2}"
|
||||
23
git-wg-peer-add
Executable file
23
git-wg-peer-add
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
PEER=$1
|
||||
IP_ADDR=$2
|
||||
EIP_ADDR=$3
|
||||
|
||||
FNAME=$(echo $PEER.wg | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
||||
|
||||
COMMIT_MSG="add peer $PEER"
|
||||
if [ -f "$FNAME" ]; then
|
||||
COMMIT_MSG="update peer $PEER"
|
||||
fi
|
||||
|
||||
echo "[Peer]
|
||||
PublicKey = $PEER
|
||||
AllowedIPs = $IP_ADDR" > "$FNAME"
|
||||
|
||||
if [ "$#" -ge 3 ]; then
|
||||
echo "Endpoint = $EIP_ADDR" >> "$FNAME"
|
||||
fi
|
||||
|
||||
|
||||
git add .
|
||||
git commit -m "$COMMIT_MSG"
|
||||
Reference in New Issue
Block a user