-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·50 lines (45 loc) · 1.02 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
#!/bin/sh
# Verbosity
DEBUG="${DEBUG:-"false"}"
if [[ ${DEBUG} == "true" ]]; then
set -xuo
fi
# VNC connection string
vnc() {
echo "VNC_USERNAME=${USER} VNC_PASSWORD=${PASSWORD} vncviewer ${HOST}"
}
# RDP connection string
rdp() {
c="xfreerdp /v:${HOST} /u:${USER} /p:${PASSWORD} +auto-reconnect "
INSECURE="${INSECURE:-"true"}"
if [[ ${INSECURE} == 'true' ]]; then c="${c} /cert:tofu "; fi
echo "${c}"
}
# Create buffered x server
DISPLAY_SEQ=$RANDOM
Xvfb :${DISPLAY_SEQ} &
while ! xdpyinfo -display :${DISPLAY_SEQ} >/dev/null 2>&1; do
sleep 0.5s;
echo "waiting for xvfb";
done
# Connection string by protocol
[[ -z "${PROTOCOL+x}" ]] \
&& echo "PROTOCOL is mandatory" \
&& exit 1
CONNECT_STRING=""
case "${PROTOCOL}" in
vnc)
CONNECT_STRING=$(vnc)
;;
rdp)
CONNECT_STRING=$(rdp)
;;
*)
echo "${PROTOCOL} is not supported. Valid values are rdp or vnc"
exit 1
;;
esac
# Connect
CONNECT="DISPLAY=:${DISPLAY_SEQ} ${CONNECT_STRING}"
eval "${CONNECT}"
exit 0