From bb527afd1fe8e7a609a7e2afa192ab2feb667af2 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Thu, 24 May 2018 21:35:09 +0200 Subject: [PATCH] add git wg update --- git-wg-peer-add | 9 +++++---- git-wg-peer-update | 13 +++++++++++++ git-wg-update | 12 ++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100755 git-wg-peer-update create mode 100755 git-wg-update diff --git a/git-wg-peer-add b/git-wg-peer-add index 0c99967..3e73c6b 100755 --- a/git-wg-peer-add +++ b/git-wg-peer-add @@ -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" diff --git a/git-wg-peer-update b/git-wg-peer-update new file mode 100755 index 0000000..e1076e6 --- /dev/null +++ b/git-wg-peer-update @@ -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" diff --git a/git-wg-update b/git-wg-update new file mode 100755 index 0000000..991ddc8 --- /dev/null +++ b/git-wg-update @@ -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