forked from sakai135/wsl-vpnkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds vpn script to start in background incl. cleanup
- Loading branch information
Showing
2 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters