mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-04-11 11:36:54 +02:00
26 lines
671 B
Bash
Executable file
26 lines
671 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
ACCOUNTS_FILE=$1
|
|
INTERFACE_NAME=$2
|
|
PUBLIC_KEY=$3
|
|
ENDPOINT=$4
|
|
ADVANCED_SECURITY=$5
|
|
|
|
ACCOUNT_STR=`grep "${PUBLIC_KEY}" "${ACCOUNTS_FILE}"`
|
|
|
|
if [ "${ACCOUNT_STR}" == "" ]; then
|
|
echo "Public key not found in accounts file!"
|
|
exit 255
|
|
fi
|
|
|
|
ACCOUNT=(${ACCOUNT_STR//,/ })
|
|
ALLOWED_IPS=$(echo ${ACCOUNT[1]}|tr -d '"')
|
|
PSK=$(echo ${ACCOUNT[2]}|tr -d '"')
|
|
PSK_FILE=$(tempfile)
|
|
echo "${PSK}" > "${PSK_FILE}"
|
|
|
|
awg set "${INTERFACE_NAME}" peer "${PUBLIC_KEY}" allowed-ips "${ALLOWED_IPS}" endpoint "${ENDPOINT}" allowed-ips "${ALLOWED_IPS}" preshared-key "${PSK_FILE}" advanced-security "${ADVANCED_SECURITY}"
|
|
EXIT_CODE=$?
|
|
|
|
rm -f "{$PSK_FILE}"
|
|
exit ${EXIT_CODE}
|