#!/bin/bash
set -eo pipefail

if ! ls dist/tv.twitch.tv.starshot* &> /dev/null; then
  echo "No IPK Found. Copy an exisiting IPK to '/dist' or build one with 'yarn build'."
  exit 1
fi

# Put the webOS CLI on path
export PATH=$WEBOS_CLI_TV:$PATH

device_name=
while [ "$1" != "" ]; do
  case $1 in
  -d | --device-name )    shift
                          device_name=$1
  esac
  shift
done

if [ -z "$device_name" ]; then
  read -rp "Device name: " device_name
fi

yarn tv:install -d "$device_name"

# The final argument should change with the the id field defined in appinfo.json
ares-launch --device "$device_name" tv.twitch.tv.starshot.lg
