#!/bin/bash

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

curr_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
source "$curr_path"/dirs

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

# Get the name of the output ipk
OUTPUT_PATH="$(ls "$WEBOS_DIR"/dist/*twitch*)"
OUTPUT_FILE="$(basename "$OUTPUT_PATH")"

ares-install --device "$device_name" "$WEBOS_DIR"/dist/"$OUTPUT_FILE"
