-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·65 lines (49 loc) · 1.1 KB
/
entrypoint.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
62
63
64
65
#!/usr/bin/env bash
set -e
echo "ARGS: $@"
echo "USER_GID: "${USER_GID:-9001}
echo "USER_UID: "${USER_UID:-9001}
# generate host keys if not present
ssh-keygen -A
# do not detach (-D), log to stderr (-e)
exec /usr/sbin/sshd -D -e &
#cd /sites
#exec openconnect "$@"
function finish {
echo "Detected SIGTERM, shuting down..."
if kill -s 0 $IKEC_PID >/dev/null 2>&1; then
echo "Stopping ikec..."
kill -TERM $IKEC_PID >/dev/null 2>&1
wait $IKEC_PID
fi
if kill -s 0 $IKED_PID >/dev/null 2>&1; then
echo "Stopping iked..."
kill -TERM $IKED_PID >/dev/null 2>&1
wait $IKED_PID
fi
}
trap finish TERM INT
SITE=$1
USERNAME=$2
PASSWORD=$3
if [ ! -f /sites/$SITE ]; then
echo "Error: /sites/$SITE does not exist."
echo "Did you forget to mount it with -v?"
exit 1
fi
COMMAND="ikec -r $SITE"
if [ ! "$USERNAME" == "" ]; then
COMMAND="$COMMAND -u $USERNAME"
fi
if [ ! "$PASSWORD" == "" ]; then
COMMAND="$COMMAND -p $PASSWORD"
fi
echo ${COMMAND}
COMMAND="${COMMAND} -a"
iked -F &
IKED_PID=$!
echo "IKEd started."
echo "Starting IKEc for $SITE..."
$COMMAND &
IKEC_PID=$!
wait $IKED_PID