-
Notifications
You must be signed in to change notification settings - Fork 4
/
tunnel
executable file
·44 lines (38 loc) · 697 Bytes
/
tunnel
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
#!/bin/bash
#port=
#user=
#host=
source .host &> /dev/null || { echo "Please set the host."; exit 1; }
name=$(basename "$0")
tunnel_cmd="ssh -CfNqT -D 1080 ${user}@${host} -p $port"
tunnel_lock=$(pgrep -xf "$tunnel_cmd")
if [[ "$#" = "1" && "$1" = "on" ]]
then
if [ -n "$tunnel_lock" ]
then
echo Tunnel is already on.
exit 1
else
eval $tunnel_cmd
if [ "$?" != "0" ]
then
echo Failed to turn on tunnel.
exit 1
fi
echo Tunnel is turned on.
fi
elif [[ "$#" = "1" && "$1" = "off" ]]
then
if [ -n "$tunnel_lock" ]
then
kill $tunnel_lock
echo Tunnel is turned off.
else
echo Tunnel is already off.
exit 1
fi
else
echo "Usage: $name on | off"
exit 1
fi
exit 0