#!/bin/sh

DNUM=13
TMP=/tmp/x11vnc_allow-connections_result
SLEEP=5 #Test duration will be more than $SLEEP * 3

# Run x11vnc on a fresh Xserver
x11vnc -create 2> /dev/null 1> /dev/null &

# Create secondary Xserver
# and connect to first trough VNC
(
  Xvfb :$DNUM -screen 0 1024x768x24 & \
  sleep $SLEEP &&                     \
  ps -ef | grep -i xvfb &&            \
  DISPLAY=:$DNUM xtigervncviewer localhost
  echo Result: $? > $TMP
) 2> /dev/null 1> /dev/null &

# Long sleep and kill VNC server
sleep $(($SLEEP * 2)) && \
killall x11vnc
sleep $SLEEP

# Check results
cat $TMP | grep '0$' 1> /dev/null
