]>
git.proxmox.com Git - mirror_novnc.git/blob - utils/launch.sh
3 # Copyright (C) 2018 The noVNC Authors
4 # Licensed under MPL 2.0 or any later version (see LICENSE.txt)
11 echo "Usage: ${NAME} [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only]"
13 echo "Starts the WebSockets proxy and a mini-webserver and "
14 echo "provides a cut-and-paste URL to go to."
16 echo " --listen PORT Port for proxy/webserver to listen on"
18 echo " --vnc VNC_HOST:PORT VNC server host:port proxy target"
19 echo " Default: localhost:5900"
20 echo " --cert CERT Path to combined cert/key file, or just"
21 echo " the cert file if used with --key"
22 echo " Default: self.pem"
23 echo " --key KEY Path to key file, when not combined with cert"
24 echo " --web WEB Path to web files (e.g. vnc.html)"
26 echo " --ssl-only Disable non-https connections."
28 echo " --record FILE Record traffic to FILE.session.js"
34 REAL_NAME
="$(readlink -f $0)"
35 HERE
="$(cd "$
(dirname "$REAL_NAME")" && pwd)"
37 VNC_DEST
="localhost:5900"
51 trap - TERM QUIT INT EXIT
52 trap "true" CHLD
# Ignore cleanup messages
54 if [ -n "${proxy_pid}" ]; then
55 echo "Terminating WebSockets proxy (${proxy_pid})"
62 # Arguments that only apply to chrooter itself
64 param
=$1; shift; OPTARG
=$1
66 --listen) PORT
="${OPTARG}"; shift ;;
67 --vnc) VNC_DEST
="${OPTARG}"; shift ;;
68 --cert) CERT
="${OPTARG}"; shift ;;
69 --key) KEY
="${OPTARG}"; shift ;;
70 --web) WEB
="${OPTARG}"; shift ;;
71 --ssl-only) SSLONLY
="--ssl-only" ;;
72 --record) RECORD_ARG
="--record ${OPTARG}"; shift ;;
74 -*) usage
"Unknown chrooter option: ${param}" ;;
80 if bash
-c "exec 7<>/dev/tcp/localhost/${PORT}" &> /dev
/null
; then
83 die
"Port ${PORT} in use. Try --listen PORT"
89 trap "cleanup" TERM QUIT INT EXIT
92 if [ -n "${WEB}" ]; then
93 if [ ! -e "${WEB}/vnc.html" ]; then
94 die
"Could not find ${WEB}/vnc.html"
96 elif [ -e "$(pwd)/vnc.html" ]; then
98 elif [ -e "${HERE}/../vnc.html" ]; then
100 elif [ -e "${HERE}/vnc.html" ]; then
102 elif [ -e "${HERE}/../share/novnc/vnc.html" ]; then
103 WEB
=${HERE}/..
/share
/novnc
/
105 die
"Could not find vnc.html"
109 if [ -n "${CERT}" ]; then
110 if [ ! -e "${CERT}" ]; then
111 die
"Could not find ${CERT}"
113 elif [ -e "$(pwd)/self.pem" ]; then
114 CERT
="$(pwd)/self.pem"
115 elif [ -e "${HERE}/../self.pem" ]; then
116 CERT
="${HERE}/../self.pem"
117 elif [ -e "${HERE}/self.pem" ]; then
118 CERT
="${HERE}/self.pem"
120 echo "Warning: could not find self.pem"
124 if [ -n "${KEY}" ]; then
125 if [ ! -e "${KEY}" ]; then
126 die
"Could not find ${KEY}"
130 # try to find websockify (prefer local, try global, then download local)
131 if [[ -d ${HERE}/websockify
]]; then
132 WEBSOCKIFY
=${HERE}/websockify
/run
134 if [[ ! -x $WEBSOCKIFY ]]; then
135 echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable."
136 echo "If you intended to use an installed websockify package, please remove ${HERE}/websockify."
140 echo "Using local websockify at $WEBSOCKIFY"
142 WEBSOCKIFY_FROMSYSTEM
=$
(which websockify
2>/dev
/null
)
143 WEBSOCKIFY_FROMSNAP
=${HERE}/..
/usr
/bin
/python2-websockify
144 [ -f $WEBSOCKIFY_FROMSYSTEM ] && WEBSOCKIFY
=$WEBSOCKIFY_FROMSYSTEM
145 [ -f $WEBSOCKIFY_FROMSNAP ] && WEBSOCKIFY
=$WEBSOCKIFY_FROMSNAP
147 if [ ! -f "$WEBSOCKIFY" ]; then
148 echo "No installed websockify, attempting to clone websockify..."
149 WEBSOCKIFY
=${HERE}/websockify
/run
150 git clone https
://github.com
/novnc
/websockify
${HERE}/websockify
152 if [[ ! -e $WEBSOCKIFY ]]; then
153 echo "Unable to locate ${HERE}/websockify/run after downloading"
157 echo "Using local websockify at $WEBSOCKIFY"
159 echo "Using installed websockify at $WEBSOCKIFY"
163 echo "Starting webserver and WebSockets proxy on port ${PORT}"
164 #${HERE}/websockify --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
165 ${WEBSOCKIFY} ${SSLONLY} --web ${WEB} ${CERT:+--cert ${CERT}} ${KEY:+--key ${KEY}} ${PORT} ${VNC_DEST} ${RECORD_ARG} &
168 if ! ps
-p ${proxy_pid} >/dev
/null
; then
170 echo "Failed to start WebSockets proxy"
174 echo -e "\n\nNavigate to this URL:\n"
175 if [ "x$SSLONLY" == "x" ]; then
176 echo -e " http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
178 echo -e " https://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
181 echo -e "Press Ctrl-C to exit\n\n"