#!/bin/bash
#
# Start/stop script for x11vnc
# Written by Zumi
#

export X11VNC="/usr/local/bin/x11vnc"

test -x $X11VNC || exit 0

case "$1" in
  start)
    if [ -s $HOME/.x11vnc/passwd ]; then
      $X11VNC -shared -forever --passwdfile $HOME/.x11vnc/passwd &
    else
      mkdir -p $HOME/.x11vnc
      xterm -bg black -fg white -e 'echo "Enter a password for the x11vnc auth:"; read PASSWORD; touch $HOME/.x11vnc/passwd; echo $PASSWORD > $HOME/.x11vnc/passwd; chmod 600 $HOME/.x11vnc/passwd'
      $X11VNC -shared -forever --passwdfile $HOME/.x11vnc/passwd &
    fi
;;

  stop)
    killall -9 x11vnc
;;

esac

export X11VNC=""

exit 0
