#!/bin/sh
#
JDSTART="sudo DISPLAY=:1 /usr/local/jdownloader/jd.sh"
XVFBSTART="sudo Xvfb :1"
case "$1" in
 start)
  echo "Starting Xvfb ..."
  screen -AmdS xvfb $XVFBSTART
  echo "Starting Jdownloader ..."
  screen -AmdS jdownloader $JDSTART
  echo "done ..."
 ;;
 stop)
  echo "Terminating jDownloader screen-session ..."
  sudo screen -S jdownloader -X quit
  echo "Terminating xvfb screen-session ..."
  sudo screen -S xvfb -X quit
  echo "done ..."
 ;;
 remote)
  echo "Starting x11"
  sudo x11vnc -display :1 -xkb
 ;;
 *)
  echo "Usage: /etc/init.d/jdownloader {start|stop|remote}"
  exit 1
 ;;
esac

exit 0