-
Notifications
You must be signed in to change notification settings - Fork 2
/
surfshark.sh
48 lines (38 loc) · 1.33 KB
/
surfshark.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
48
#!/bin/sh
surfshark_username="${SHARK_USERNAME:[email protected]}"
surfshark_password="${SHARK_PASSWORD:-password}"
login_payload_template='{"username":"%s","password":"%s"}'
login_payload=$(printf "$login_payload_template" "$surfshark_username" "$surfshark_password")
echo "Initialising Surfshark SmartDNS Updater v2.0"
ipfile="/tmp/ss_ipfile.dat"
old_ip=""
new_ip=`curl -s 'https://api.ipify.org'`
if [ -f "$ipfile" ]
then
old_ip=`head -n 1 $ipfile`
fi
if [ "$old_ip" = "$new_ip" ]
then
echo "Old/New IP are the same, no update needed"
exit 0
fi
echo "Logging in with username $surfshark_username"
login_request=`curl -s -X POST "https://api.surfshark.com/v1/auth/login" -H "Content-Type: application/json" --data $login_payload`
if [ -z "$login_request" ]
then
echo "Login failed. Check your username or password"
exit 1
else
bearer_token=`echo $login_request | awk -F "[,:}]" '{print $2}' | tr -d '"'`
echo "Logged in successfully"
fi
update_request=`curl -s -X POST "https://api.surfshark.com/v1/server/smart-dns" -H "Authorization: Bearer $bearer_token"`
user_ip=`echo $update_request | awk -F "[,:}]" '{print $4}' | tr -d '"'`
if [ "$user_ip" = "Invalid JWT Token" ]
then
echo "Update failed - Payload $update_request"
exit 1
else
echo $new_ip | tee $ipfile
echo "Updated SmartDNS IP to $user_ip"
fi