CoolFace
Apppublic

xXLuciferXx/Nexus

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
launch.sh168 linesDownload Raw Back to root
1#!/usr/bin/env bash2 3# Copyright (C) 2018 The noVNC Authors4# Licensed under MPL 2.0 or any later version (see LICENSE.txt)5 6usage() {7    if [ "$*" ]; then8        echo "$*"9        echo10    fi11    echo "Usage: ${NAME} [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only]"12    echo13    echo "Starts the WebSockets proxy and a mini-webserver and "14    echo "provides a cut-and-paste URL to go to."15    echo16    echo "    --listen PORT         Port for proxy/webserver to listen on"17    echo "                          Default: 6080"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"21    echo "                          Default: self.pem"22    echo "    --web WEB             Path to web files (e.g. vnc.html)"23    echo "                          Default: ./"24    echo "    --ssl-only            Disable non-https connections."25    echo "                                    "26    echo "    --record FILE         Record traffic to FILE.session.js"27    echo "                                    "28    exit 229}30 31NAME="$(basename $0)"32REAL_NAME="$(readlink -f $0)"33HERE="$(cd "$(dirname "$REAL_NAME")" && pwd)"34PORT="6080"35VNC_DEST="localhost:5900"36CERT=""37WEB=""38proxy_pid=""39SSLONLY=""40RECORD_ARG=""41 42die() {43    echo "$*"44    exit 145}46 47cleanup() {48    trap - TERM QUIT INT EXIT49    trap "true" CHLD   # Ignore cleanup messages50    echo51    if [ -n "${proxy_pid}" ]; then52        echo "Terminating WebSockets proxy (${proxy_pid})"53        kill ${proxy_pid}54    fi55}56 57# Process Arguments58 59# Arguments that only apply to chrooter itself60while [ "$*" ]; do61    param=$1; shift; OPTARG=$162    case $param in63    --listen)  PORT="${OPTARG}"; shift            ;;64    --vnc)     VNC_DEST="${OPTARG}"; shift        ;;65    --cert)    CERT="${OPTARG}"; shift            ;;66    --web)     WEB="${OPTARG}"; shift            ;;67    --ssl-only) SSLONLY="--ssl-only"             ;;68    --record) RECORD_ARG="--record ${OPTARG}"; shift ;;69    -h|--help) usage                              ;;70    -*) usage "Unknown chrooter option: ${param}" ;;71    *) break                                      ;;72    esac73done74 75# Sanity checks76if bash -c "exec 7<>/dev/tcp/localhost/${PORT}" &> /dev/null; then77    exec 7<&-78    exec 7>&-79    die "Port ${PORT} in use. Try --listen PORT"80else81    exec 7<&-82    exec 7>&-83fi84 85trap "cleanup" TERM QUIT INT EXIT86 87# Find vnc.html88if [ -n "${WEB}" ]; then89    if [ ! -e "${WEB}/vnc.html" ]; then90        die "Could not find ${WEB}/vnc.html"91    fi92elif [ -e "$(pwd)/vnc.html" ]; then93    WEB=$(pwd)94elif [ -e "${HERE}/../vnc.html" ]; then95    WEB=${HERE}/../96elif [ -e "${HERE}/vnc.html" ]; then97    WEB=${HERE}98elif [ -e "${HERE}/../share/novnc/vnc.html" ]; then99    WEB=${HERE}/../share/novnc/100else101    die "Could not find vnc.html"102fi103 104# Find self.pem105if [ -n "${CERT}" ]; then106    if [ ! -e "${CERT}" ]; then107        die "Could not find ${CERT}"108    fi109elif [ -e "$(pwd)/self.pem" ]; then110    CERT="$(pwd)/self.pem"111elif [ -e "${HERE}/../self.pem" ]; then112    CERT="${HERE}/../self.pem"113elif [ -e "${HERE}/self.pem" ]; then114    CERT="${HERE}/self.pem"115else116    echo "Warning: could not find self.pem"117fi118 119# try to find websockify (prefer local, try global, then download local)120if [[ -e ${HERE}/websockify ]]; then121    WEBSOCKIFY=${HERE}/websockify/run122 123    if [[ ! -x $WEBSOCKIFY ]]; then124        echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable."125        echo "If you intended to use an installed websockify package, please remove ${HERE}/websockify."126        exit 1127    fi128 129    echo "Using local websockify at $WEBSOCKIFY"130else131    WEBSOCKIFY=$(which websockify 2>/dev/null)132 133    if [[ $? -ne 0 ]]; then134        echo "No installed websockify, attempting to clone websockify..."135        WEBSOCKIFY=${HERE}/websockify/run136        git clone https://github.com/novnc/websockify ${HERE}/websockify137 138        if [[ ! -e $WEBSOCKIFY ]]; then139            echo "Unable to locate ${HERE}/websockify/run after downloading"140            exit 1141        fi142 143        echo "Using local websockify at $WEBSOCKIFY"144    else145        echo "Using installed websockify at $WEBSOCKIFY"146    fi147fi148 149echo "Starting webserver and WebSockets proxy on port ${PORT}"150#${HERE}/websockify --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &151${WEBSOCKIFY} ${SSLONLY} --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} ${RECORD_ARG} &152proxy_pid="$!"153sleep 1154if ! ps -p ${proxy_pid} >/dev/null; then155    proxy_pid=156    echo "Failed to start WebSockets proxy"157    exit 1158fi159 160echo -e "\n\nNavigate to this URL:\n"161if [ "x$SSLONLY" == "x" ]; then162    echo -e "    http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"163else164    echo -e "    https://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"165fi166 167echo -e "Press Ctrl-C to exit\n\n"168