forked from sakai135/wsl-vpnkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpn
executable file
·52 lines (35 loc) · 1.02 KB
/
vpn
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
#!/usr/bin/env bash
# starts the wsl-vpnkit in a tmux sessions and cleanup beforehand, based on https://github.com/sakai135/wsl-vpnkit/issues/13
echo $BASH_SOURCE
echo $0
ME=$(readlink -f "$BASH_SOURCE")
if [ ! "$(id -u)" = "0" ]; then
echo "Not root, calling self as root..."
sudo -E sh -c $ME
exit "$?"
else
echo "Running as root..."
fi
set -x
function kill_vpnkit(){
SIG=$2
MSG=$1
if ps -ef | grep -v grep | grep "bash ./wsl-vpnkit" >/dev/null; then
echo $MSG
for i in $(ps -ef | grep "bash ./wsl-vpnkit" | grep -v grep | awk '{print $2}'); do kill $SIG $i; done
fi
}
kill_vpnkit "Graceful kill of older processes..."
#first graceful kill
if ps -ef | grep -v grep | grep "bash ./wsl-vpnkit" >/dev/null; then
echo "Wait 60 sec for graceful death..."
sleep 20
fi
kill_vpnkit "Not so graceful kill of older processes..." -9
#startup
echo "Starting up..."
cd ~/bin/wsl-vpnkit
if [ -f "$ME.out" ]; then
mv $ME.out $ME.out.$(date +'%Y%m%d%H%M%S')
fi
tmux new -s wsl-vpnkit -d "./wsl-vpnkit > ./wsl-vpnkit.out 2>&1"