#!/bin/bash

function main() {
     case $1 in
      "" ) start ;;
      "start" ) start ;;
      "stop" ) stop ;;
      * ) helpTxt; exit;;
     esac
}

function start() {
    if ! [ -e resources/image ]; then
        mkfifo resources/image
    fi

    java -Xms32m -Xmx52m -jar resources/GrabScreen.jar > resources/image & export PID=$!
    echo "${PID}" > resources/PID
    echo "Dsktop Capture Started..."
}

function stop() {
    kill $(cat resources/PID)
    echo "Dsktop Capture Stopped..."
}

function helpTxt() {
    echo -e "Try one of these commands:\n" \
            "start\n" \
            "stop"
}
main $@;
