#!/bin/bash
set -e

function color {
  tput bold
  tput setaf "$1"
  shift
  echo "$@"
  tput sgr0
}
function green {
  color 2 "$@"
}
function blue {
  color 4 "$@"
}

blue "Setting up a new LG TV connection"

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

blue "Follow the instructions to set up a new TV"
ares-setup-device

ares-setup-device --list

blue "On your TV, click the 'Key Server' button in the Developer Mode app"

blue "Enter the device name you used in the previous step"
read -rp "Device name: " device_name

blue "Enter the Passphrase as shown on your TV screen in the bottom left of the Developer Mode app"
ares-novacom --device "$device_name" --getkey

blue "Checking connection with TV..."
ares-install --device "$device_name" --list

green "Setup complete!"
