-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewclient.sh
More file actions
executable file
·63 lines (49 loc) · 1.4 KB
/
newclient.sh
File metadata and controls
executable file
·63 lines (49 loc) · 1.4 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
cd /etc/wireguard
CONFIGFILE="wg0.conf"
DEFAULTIP="10.0.0."
MASK="/32"
GREEN='\033[0;32m'
NC='\033[0m'
echo "====j2wj wireguard new client===="
usage()
{
echo "USAGE: ./newclient.sh clent1 client2 ...clientN, where N >= 1"
}
if [[ $# -eq 0 ]]
then
usage
exit 1
fi
for var in "$@"
do
wg genkey | tee ${var}_privatekey | wg pubkey > ${var}_publickey
pbkey=$(cat ${var}_publickey)
prkey=$(cat ${var}_privatekey)
serverPubKey=$(cat publickey)
serverIp=$(hostname -i)
ipLS=$(grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' $CONFIGFILE | tail -1 | cut -d . -f 4)
ipLS=$(($ipLS + 1))
resultIp="${DEFAULTIP}${ipLS}${MASK}"
echo "" >> $CONFIGFILE
echo "#$var" >> $CONFIGFILE
echo "[Peer]" >> $CONFIGFILE
echo "PublicKey = $pbkey" >> $CONFIGFILE
echo "AllowedIPs = $resultIp" >> $CONFIGFILE
echo -e "${GREEN}$var privatekey:${NC}\t $prkey"
echo -e "${GREEN}$var ip:${NC}\t\t $resultIp"
echo ""
CONFIG=""
CONFIG="${CONFIG}[Interface]\n"
CONFIG="${CONFIG}PrivateKey = ${prkey}\n"
CONFIG="${CONFIG}Address = ${resultIp}\n"
CONFIG="${CONFIG}DNS = 8.8.8.8\n\n"
CONFIG="${CONFIG}[Peer]\n"
CONFIG="${CONFIG}PublicKey = ${serverPubKey}\n"
CONFIG="${CONFIG}Endpoint = ${serverIp}:51830\n"
CONFIG="${CONFIG}AllowedIPs = 0.0.0.0/0\n\n"
echo -e $CONFIG > ${var}.conf
qrencode -t ansiutf8 < ${var}.conf
done
systemctl restart wg-quick@wg0
systemctl status wg-quick@wg0 | head -n 3