#!/bin/bash

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# Copyright (C) 2021 Malcolm Lewis <malcolmlewis@opensuse.org>

# Description: Script to start/stop UxPlay
# Version: 0.0.4
# Date: 12th April, 2021

case "$1" in
    start)
        test ! -f /run/user/`id -u`/uxplay.lock || { echo "UxPlay is already running...";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }
        touch /run/user/`id -u`/uxplay.lock
        /usr/bin/uxplay > /dev/null 2>&1 &
        echo "UxPlay started..."
        ;;
    stop)
        test -f /run/user/`id -u`/uxplay.lock || { echo "UxPlay is already stopped...";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }
        killall "/usr/bin/uxplay"
        rm -f /run/user/`id -u`/uxplay.lock
        echo "UxPlay stopped..."
        ;;
        *)
	echo "Usage: $0 {start|stop}"
	exit 1
;;
esac

