-
Notifications
You must be signed in to change notification settings - Fork 4
/
startup-socat.sh
executable file
·61 lines (48 loc) · 1.17 KB
/
startup-socat.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
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
if [ "$#" -ne 5 ]; then
echo -e "usage:\n\$ docker run -ti -p [PORT]:[PORT] --privileged --name ike debian-ike:0.1 \"[CONFIG]\" [USER] [PW] [TARGET] [PORT]"
exit 1
fi
BASENAME=`basename "$0"`
CONFIG=$1
USER=$2
PW=$3
TARGET=$4
PORT=$5
IKED_PID=$(pgrep iked)
if [ -z "${IKED_PID}" ]; then
iked &
fi
# command -v /usr/bin/nano >/dev/null 2>&1 || { echo "please make sure nano is installed. aborting..." >&2; exit 1; }
# set nano as git editor
if [ -f /usr/bin/nano ]; then
if [ -f /usr/bin/git ]; then
git config --global core.editor "nano"
fi
fi
function finish {
echo "Detected SIGTERM, shuting down..."
killall -9 ikec &>/dev/null
killall -9 socat &>/dev/null
exit 0
}
trap finish TERM INT
check_vpn () {
# Check for specific interface
TUNNEL=$(ifconfig | grep "tap0")
# echo "$TUNNEL"
if [ -n "$TUNNEL" ]; then
echo "$(date +"%T") - $BASENAME: tap0 is up"
sleep 20
else
echo "$(date +"%T") - $BASENAME: tap0 is down. reconnecting.."
killall -9 ikec &>/dev/null
killall -9 socat &>/dev/null
socat TCP4-LISTEN:${PORT},fork TCP4:${TARGET} &
ikec -r "${CONFIG}" -u ${USER} -p ${PW} -a &
sleep 10
fi
check_vpn
}
check_vpn
exit 0