]>
git.proxmox.com Git - mirror_novnc.git/blob - utils/launch.sh
3 # Copyright 2016 Joel Martin
4 # Copyright 2016 Solly Ross
5 # Licensed under MPL 2.0 or any later version (see LICENSE.txt)
12 echo "Usage: ${NAME} [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only]"
14 echo "Starts the WebSockets proxy and a mini-webserver and "
15 echo "provides a cut-and-paste URL to go to."
17 echo " --listen PORT Port for proxy/webserver to listen on"
19 echo " --vnc VNC_HOST:PORT VNC server host:port proxy target"
20 echo " Default: localhost:5900"
21 echo " --cert CERT Path to combined cert/key file"
22 echo " Default: self.pem"
23 echo " --web WEB Path to web files (e.g. vnc.html)"
25 echo " --ssl-only Disable non-https connections."
31 REAL_NAME
="$(readlink -f $0)"
32 HERE
="$(cd "$
(dirname "$REAL_NAME")" && pwd)"
34 VNC_DEST
="localhost:5900"
46 trap - TERM QUIT INT EXIT
47 trap "true" CHLD
# Ignore cleanup messages
49 if [ -n "${proxy_pid}" ]; then
50 echo "Terminating WebSockets proxy (${proxy_pid})"
57 # Arguments that only apply to chrooter itself
59 param
=$1; shift; OPTARG
=$1
61 --listen) PORT
="${OPTARG}"; shift ;;
62 --vnc) VNC_DEST
="${OPTARG}"; shift ;;
63 --cert) CERT
="${OPTARG}"; shift ;;
64 --web) WEB
="${OPTARG}"; shift ;;
65 --ssl-only) SSLONLY
="--ssl-only" ;;
67 -*) usage
"Unknown chrooter option: ${param}" ;;
73 which netstat
>/dev
/null
2>&1 \
74 || die
"Must have netstat installed"
76 netstat
-ltn |
grep -qs ":${PORT} .*LISTEN" \
77 && die
"Port ${PORT} in use. Try --listen PORT"
79 trap "cleanup" TERM QUIT INT EXIT
82 if [ -n "${WEB}" ]; then
83 if [ ! -e "${WEB}/vnc.html" ]; then
84 die
"Could not find ${WEB}/vnc.html"
86 elif [ -e "$(pwd)/vnc.html" ]; then
88 elif [ -e "${HERE}/../vnc.html" ]; then
90 elif [ -e "${HERE}/vnc.html" ]; then
92 elif [ -e "${HERE}/../share/novnc/vnc.html" ]; then
93 WEB
=${HERE}/..
/share
/novnc
/
95 die
"Could not find vnc.html"
99 if [ -n "${CERT}" ]; then
100 if [ ! -e "${CERT}" ]; then
101 die
"Could not find ${CERT}"
103 elif [ -e "$(pwd)/self.pem" ]; then
104 CERT
="$(pwd)/self.pem"
105 elif [ -e "${HERE}/../self.pem" ]; then
106 CERT
="${HERE}/../self.pem"
107 elif [ -e "${HERE}/self.pem" ]; then
108 CERT
="${HERE}/self.pem"
110 echo "Warning: could not find self.pem"
113 # try to find websockify (prefer local, try global, then download local)
114 if [[ -e ${HERE}/websockify
]]; then
115 WEBSOCKIFY
=${HERE}/websockify
/run
117 if [[ ! -x $WEBSOCKIFY ]]; then
118 echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable."
119 echo "If you intended to use an installed websockify package, please remove ${HERE}/websockify."
123 echo "Using local websockify at $WEBSOCKIFY"
125 WEBSOCKIFY
=$
(which websockify
2>/dev
/null
)
127 if [[ $?
-ne 0 ]]; then
128 echo "No installed websockify, attempting to clone websockify..."
129 WEBSOCKIFY
=${HERE}/websockify
/run
130 git clone https
://github.com
/novnc
/websockify
${HERE}/websockify
132 if [[ ! -e $WEBSOCKIFY ]]; then
133 echo "Unable to locate ${HERE}/websockify/run after downloading"
137 echo "Using local websockify at $WEBSOCKIFY"
139 echo "Using installed websockify at $WEBSOCKIFY"
143 echo "Starting webserver and WebSockets proxy on port ${PORT}"
144 #${HERE}/websockify --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
145 ${WEBSOCKIFY} ${SSLONLY} --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
148 if ! ps
-p ${proxy_pid} >/dev
/null
; then
150 echo "Failed to start WebSockets proxy"
154 echo -e "\n\nNavigate to this URL:\n"
155 if [ "x$SSLONLY" == "x" ]; then
156 echo -e " http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
158 echo -e " https://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
161 echo -e "Press Ctrl-C to exit\n\n"