add git wg update
This commit is contained in:
@@ -3,6 +3,7 @@ PEER=$1
|
||||
IP_ADDR=$2
|
||||
EIP_ADDR=$3
|
||||
|
||||
set -e
|
||||
FNAME=$(echo $PEER.wg | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
||||
|
||||
COMMIT_MSG="add peer $PEER"
|
||||
@@ -11,13 +12,13 @@ if [ -f "$FNAME" ]; then
|
||||
fi
|
||||
|
||||
echo "[Peer]
|
||||
PublicKey = $PEER
|
||||
AllowedIPs = $IP_ADDR" > "$FNAME"
|
||||
public-key = $PEER
|
||||
allowed-ips = $IP_ADDR" > "$FNAME"
|
||||
|
||||
if [ "$#" -ge 3 ]; then
|
||||
echo "Endpoint = $EIP_ADDR" >> "$FNAME"
|
||||
echo "endpoints = $EIP_ADDR" >> "$FNAME"
|
||||
fi
|
||||
|
||||
|
||||
git add .
|
||||
git add "$FNAME"
|
||||
git commit -m "$COMMIT_MSG"
|
||||
|
||||
13
git-wg-peer-update
Executable file
13
git-wg-peer-update
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
PEER=$1
|
||||
KEY=$2
|
||||
VALUE=$3
|
||||
|
||||
set -e
|
||||
FNAME=$(echo $PEER.wg | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
||||
|
||||
sed -i "s/$KEY =.*/$KEY = $VALUE/g" "$FNAME"
|
||||
|
||||
|
||||
git add "$FNAME"
|
||||
git commit -m "update $KEY of peer $PEER to $VALUE"
|
||||
12
git-wg-update
Executable file
12
git-wg-update
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
KEY=$1
|
||||
NETWORK=${2:-${PWD##*/}}
|
||||
mapfile -t LINES <<< "$(sudo wg show $NETWORK $KEY)"
|
||||
|
||||
for i in "${LINES[@]}"; do
|
||||
if [ -n "$i" ]; then
|
||||
PEER=$(echo $i | awk -F ' ' '{print $1}')
|
||||
VALUE=$(echo $i | awk -F ' ' '{$1="";print $0}')
|
||||
git-wg-peer-update "$PEER" "$KEY" "$VALUE"
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user