-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete.sh
executable file
·47 lines (39 loc) · 1.09 KB
/
delete.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
source config.sh
source util.sh
# CMD Line args
if [ "$1" == '' ]; then
echo "USAGE: ./delete.sh clientName"
echo ""
listSetUpClients
exit
fi
# Main
CLIENTNAME=${1//.conf/}
if [ -f "${CONFKEYDIR}/${CLIENTNAME}.conf" ]; then
read -p "Delete keys for $CLIENTNAME? [Y/n] " -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
PUBKEY=`cat ${CONFKEYDIR}/${CLIENTNAME}.key.pub`
rm ${CONFKEYDIR}/${CLIENTNAME}.*
fi
echo "Choose which interface to remove the key from: "
arraylength=${#WGINTERFACES[@]}
for (( i=0; i<${arraylength}; i++ )); do
echo "${i}: ${WGINTERFACES[$i]}"
done
while read -p "Remove on interface: " -r i; do
if [ $i -lt $arraylength ] && [ $i -gt -1 ]; then
interface=${WGINTERFACES[$i]}
sudo wg set $interface peer $PUBKEY remove
echo "Removed $CLIENTNAME from $interface"
else
echo "Chosen interface not in range."
fi
done
read -p "Restart wg service? Recommended, but will drop connections momentarily. [Y/n] " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
turnWgIfaceOnOff $interface restart
fi
else
echo "Client key with that name doesn't exist"
fi