From e40fb2f711269b8346b5720b597fe6a324a6647c Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Thu, 29 Apr 2021 16:52:06 +0200 Subject: [PATCH] First try of use of wg-portal API --- wireguard/peer_install.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 wireguard/peer_install.sh diff --git a/wireguard/peer_install.sh b/wireguard/peer_install.sh new file mode 100755 index 0000000..f9cfb68 --- /dev/null +++ b/wireguard/peer_install.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +WGPORTAL_URL=http://185.123.84.125:8123/ +WG_CONFFILE=/etc/wireguard/wg0.conf + +trap 'stty echo' INT + +if [ -f "$WG_CONFFILE" -a $OVERWRITE -ne 1 ]; then + printf "Wireguard config file already exists\n" + printf "Exiting now to prevent overrid of your actual parameters\n" + exit 1; +fi + +printf "Username: " +IFS= read -r username + +printf "Password: " +stty -echo +IFS= read -r password +stty echo +printf "\n" + +HTTP_STATUS=$(curl -w "%{http_code}" -s -o $WG_CONFFILE --user $username:$password -X GET $WGPORTAL_URL"api/v1/provisioning/peer/mqQiS1kYWDoXlvhucqMIGkBeUjy7yppZ0eLLENsM5UU%3D" -H "accept: text/plain") +res=$? +if test "$res" != "0"; then + echo "the curl command failed with: $res" +fi +