#!/bin/bash
echo "Stardard DreamPi Service - Stopping ..."
sudo pgrep -f dreampi_now.py | sudo xargs kill -9 2>/dev/null &
sudo service dreampi stop
echo "Stardard DreamPi Service - Stopped"
echo "--------------------------------------"
echo "Autonomous Dreamcast Now Service - Starting ..."

echo ""
echo "1 - Phantasy Star Online"
echo "2 - Quake III Arena"
echo "3 - 4x4 Evolution"
echo "4 - Alien Front Online"
echo "5 - ChuChu Rocket"
echo "6 - Internet Game Pack (after game login)"
echo "7 - Maximum Pool"
echo "8 - Mobile Suit Gundam: Federation vs. Zeon"
echo "9 - Monaco Grand Prix Online"
echo "10 - Next Tetris"
echo "11 - Ooga Booga"
echo "12 - PBA Bowling"
echo "13 - POD Speedzone"
echo "14 - Planet Ring"
echo "15 - Starlancer"
echo "16 - Toy Racer"
echo "17 - Worms World Party"
echo "18 - Stop last session and restart DreamPi (modem)"
echo ""
echo "Note: 2K Sports Games online functions don't work out of DreamPi, so can't be selected"
echo ""
echo "Choose game number: "

read n

chk='^[0-9]+$'

if ! [[ $n =~ $chk ]]
then
  echo "Not a number"
  exit 0
fi

if [ $n -gt 18 ] || [ $n -lt 1 ]
then
  echo "Invalid option"
elif [[ $n -eq 18 ]]
then
  echo "Restarting Standard DreamPi (modem)"
  sudo service dreampi restart &
else
  sudo python2.7 dreampi_now.py $n --no-daemon &
  echo ""
  sleep 12
  echo "Running in background"
  echo ""
fi
exit 0
