#!/bin/bash

VNC=novnc
XVNC=Xvnc

XVNC_HOST=0.0.0.0
XVNC_PORT=5901

DISPLAY_WIDTH=$1
DISPLAY_HEIGHT=$2

if ! command -v novnc &> /dev/null; then
    echo "NoVnc installation missing! Aborting..."
    exit 1
fi

if ! command -v Xvnc &> /dev/null; then
    echo "X server or vnc extention missing! Aborting..."
    exit 1
fi

$XVNC :1 \
    -geometry ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} \
    -depth 24 \
    -SecurityTypes None \
    -interface $XVNC_HOST \
    -rfbport $XVNC_PORT \
    &

sleep 2

$VNC --vnc localhost:5901 &

sleep 2

export DISPLAY=:1

exec ./miniRT
