]>
git.proxmox.com Git - mirror_novnc.git/blob - utils/launch.sh
8 echo "Usage: ${NAME} [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT]"
10 echo "Starts the WebSockets proxy and a mini-webserver and "
11 echo "provides a cut-and-paste URL to go to."
13 echo " --listen PORT Port for proxy/webserver to listen on"
15 echo " --vnc VNC_HOST:PORT VNC server host:port proxy target"
16 echo " Default: localhost:5900"
17 echo " --cert CERT Path to combined cert/key file"
18 echo " Default: self.pem"
19 echo " --web WEB Path to web files (e.g. vnc.html)"
25 REAL_NAME
="$(readlink -f $0)"
26 HERE
="$(cd "$
(dirname "$REAL_NAME")" && pwd)"
28 VNC_DEST
="localhost:5900"
39 trap - TERM QUIT INT EXIT
40 trap "true" CHLD
# Ignore cleanup messages
42 if [ -n "${proxy_pid}" ]; then
43 echo "Terminating WebSockets proxy (${proxy_pid})"
50 # Arguments that only apply to chrooter itself
52 param
=$1; shift; OPTARG
=$1
54 --listen) PORT
="${OPTARG}"; shift ;;
55 --vnc) VNC_DEST
="${OPTARG}"; shift ;;
56 --cert) CERT
="${OPTARG}"; shift ;;
57 --web) WEB
="${OPTARG}"; shift ;;
59 -*) usage
"Unknown chrooter option: ${param}" ;;
65 which netstat
>/dev
/null
2>&1 \
66 || die
"Must have netstat installed"
68 netstat
-ltn |
grep -qs "${PORT} .*LISTEN" \
69 && die
"Port ${PORT} in use. Try --listen PORT"
71 trap "cleanup" TERM QUIT INT EXIT
74 if [ -n "${WEB}" ]; then
75 if [ ! -e "${WEB}/vnc.html" ]; then
76 die
"Could not find ${WEB}/vnc.html"
78 elif [ -e "$(pwd)/vnc.html" ]; then
80 elif [ -e "${HERE}/../vnc.html" ]; then
82 elif [ -e "${HERE}/vnc.html" ]; then
84 elif [ -e "${HERE}/../share/novnc/vnc.html" ]; then
85 WEB
=${HERE}/..
/share
/novnc
/
87 die
"Could not find vnc.html"
91 if [ -n "${CERT}" ]; then
92 if [ ! -e "${CERT}" ]; then
93 die
"Could not find ${CERT}"
95 elif [ -e "$(pwd)/self.pem" ]; then
96 CERT
="$(pwd)/self.pem"
97 elif [ -e "${HERE}/../self.pem" ]; then
98 CERT
="${HERE}/../self.pem"
99 elif [ -e "${HERE}/self.pem" ]; then
100 CERT
="${HERE}/self.pem"
102 echo "Warning: could not find self.pem"
105 # try to find websockify (prefer local, try global, then download local)
106 if [[ -e ${HERE}/websockify
]]; then
107 WEBSOCKIFY
=${HERE}/websockify
/run
109 if [[ ! -x $WEBSOCKIFY ]]; then
110 echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable."
111 echo "If you inteded to use an installed websockify package, please remove ${HERE}/websockify."
115 echo "Using local websockify at $WEBSOCKIFY"
117 WEBSOCKIFY
=$
(which websockify
2>/dev
/null
)
119 if [[ $?
-ne 0 ]]; then
120 echo "No installed websockify, attempting to clone websockify..."
121 WEBSOCKIFY
=${HERE}/websockify
/run
122 git clone https
://github.com
/kanaka
/websockify
${HERE}/websockify
124 if [[ ! -e $WEBSOCKIFY ]]; then
125 echo "Unable to locate ${HERE}/websockify/run after downloading"
129 echo "Using local websockify at $WEBSOCKIFY"
131 echo "Using installed websockify at $WEBSOCKIFY"
135 echo "Starting webserver and WebSockets proxy on port ${PORT}"
136 #${HERE}/websockify --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
137 ${WEBSOCKIFY} --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
140 if ! ps
-p ${proxy_pid} >/dev
/null
; then
142 echo "Failed to start WebSockets proxy"
146 echo -e "\n\nNavigate to this URL:\n"
147 echo -e " http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
148 echo -e "Press Ctrl-C to exit\n\n"