]>
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]"
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)"
29 REAL_NAME
="$(readlink -f $0)"
30 HERE
="$(cd "$
(dirname "$REAL_NAME")" && pwd)"
32 VNC_DEST
="localhost:5900"
43 trap - TERM QUIT INT EXIT
44 trap "true" CHLD
# Ignore cleanup messages
46 if [ -n "${proxy_pid}" ]; then
47 echo "Terminating WebSockets proxy (${proxy_pid})"
54 # Arguments that only apply to chrooter itself
56 param
=$1; shift; OPTARG
=$1
58 --listen) PORT
="${OPTARG}"; shift ;;
59 --vnc) VNC_DEST
="${OPTARG}"; shift ;;
60 --cert) CERT
="${OPTARG}"; shift ;;
61 --web) WEB
="${OPTARG}"; shift ;;
63 -*) usage
"Unknown chrooter option: ${param}" ;;
69 which netstat
>/dev
/null
2>&1 \
70 || die
"Must have netstat installed"
72 netstat
-ltn |
grep -qs ":${PORT} .*LISTEN" \
73 && die
"Port ${PORT} in use. Try --listen PORT"
75 trap "cleanup" TERM QUIT INT EXIT
78 if [ -n "${WEB}" ]; then
79 if [ ! -e "${WEB}/vnc.html" ]; then
80 die
"Could not find ${WEB}/vnc.html"
82 elif [ -e "$(pwd)/vnc.html" ]; then
84 elif [ -e "${HERE}/../vnc.html" ]; then
86 elif [ -e "${HERE}/vnc.html" ]; then
88 elif [ -e "${HERE}/../share/novnc/vnc.html" ]; then
89 WEB
=${HERE}/..
/share
/novnc
/
91 die
"Could not find vnc.html"
95 if [ -n "${CERT}" ]; then
96 if [ ! -e "${CERT}" ]; then
97 die
"Could not find ${CERT}"
99 elif [ -e "$(pwd)/self.pem" ]; then
100 CERT
="$(pwd)/self.pem"
101 elif [ -e "${HERE}/../self.pem" ]; then
102 CERT
="${HERE}/../self.pem"
103 elif [ -e "${HERE}/self.pem" ]; then
104 CERT
="${HERE}/self.pem"
106 echo "Warning: could not find self.pem"
109 # try to find websockify (prefer local, try global, then download local)
110 if [[ -e ${HERE}/websockify
]]; then
111 WEBSOCKIFY
=${HERE}/websockify
/run
113 if [[ ! -x $WEBSOCKIFY ]]; then
114 echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable."
115 echo "If you intended to use an installed websockify package, please remove ${HERE}/websockify."
119 echo "Using local websockify at $WEBSOCKIFY"
121 WEBSOCKIFY
=$
(which websockify
2>/dev
/null
)
123 if [[ $?
-ne 0 ]]; then
124 echo "No installed websockify, attempting to clone websockify..."
125 WEBSOCKIFY
=${HERE}/websockify
/run
126 git clone https
://github.com
/kanaka
/websockify
${HERE}/websockify
128 if [[ ! -e $WEBSOCKIFY ]]; then
129 echo "Unable to locate ${HERE}/websockify/run after downloading"
133 echo "Using local websockify at $WEBSOCKIFY"
135 echo "Using installed websockify at $WEBSOCKIFY"
139 echo "Starting webserver and WebSockets proxy on port ${PORT}"
140 #${HERE}/websockify --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
141 ${WEBSOCKIFY} --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
144 if ! ps
-p ${proxy_pid} >/dev
/null
; then
146 echo "Failed to start WebSockets proxy"
150 echo -e "\n\nNavigate to this URL:\n"
151 echo -e " http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
152 echo -e "Press Ctrl-C to exit\n\n"