#!/bin/bash

if [ ! -e /usr/games/gnome-mastermind ]; then
  echo "gnome-mastermind binary not found in /usr/games/"
  exit 1
fi

xvfb-run -a /usr/games/gnome-mastermind &
sleep 5

# Get PID, match exact to not get 2 PIDs
pidret=`pgrep -xf "/usr/games/gnome-mastermind"`

if [ ! $pidret ]; then
  echo "/usr/games/gnome-mastermind process not found"
  exit 1
fi

# Kill processes
kill -9 $pidret

ret=$?

if [ $ret == 0 ]; then
  echo "gnome-mastermind opened and closed successfully"
fi

exit $ret

