Change add command to use public key as optional param

This commit is contained in:
2022-12-17 09:44:40 +01:00
parent 133c466c26
commit 1bb1be36f8
3 changed files with 35 additions and 3 deletions

View File

@ -15,8 +15,13 @@ if [ -z $CLIENT_ID ]; then
exit 1
fi
CLIENT_SEC_KEY=$(wg genkey)
CLIENT_PUB_KEY=$(echo $CLIENT_SEC_KEY | wg pubkey)
if [ -z $1 ]; then
CLIENT_SEC_KEY=$(wg genkey)
CLIENT_PUB_KEY=$(echo $CLIENT_SEC_KEY | wg pubkey)
else
CLIENT_SEC_KEY="<place secret key here>"
CLIENT_PUB_KEY=$1
fi
# Add peer config
cat << EOF >> $DEVICE.conf
@ -53,4 +58,8 @@ AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = $SERVER_HOST:$SERVER_PORT
EOF
echo "Added Client # $CLIENT_ID"
if [ -z $1 ]; then
echo "Added Client # $CLIENT_ID"
else
echo "Added Client # $CLIENT_ID with existing public key"
fi

View File

@ -13,6 +13,11 @@ case "$1" in
exit 0
;;
'add-client' | 'add')
if [ ! -z $2 ]; then
cd /etc/wireguard
/scripts/add-client.sh $2
exit 0
fi
cd /etc/wireguard
/scripts/add-client.sh
exit 0