#!/bin/bash
#
# Sets the ip address for a yeti
#
# Warning, this script makes an assumption about the 

OLD_IPADDR=$1
NEW_IPADDR=$2
echo "-------------------------------------------------------------------------"
echo "Changing IP Address from ${OLD_IPADDR} to ${NEW_IPADDR}"
echo ""
echo "**Warning**"
echo "This script will hang after setting the remote ip address.  Use 'ctrl+c' to exit"
echo ""
echo "Removing host from known hosts"
ssh-keygen -f ~/.ssh/known_hosts -R ${OLD_IPADDR}
echo ""
echo "*******************"
echo "password is 'root'"
echo "*******************"
services="$(ssh root@${OLD_IPADDR} "connmanctl services;")"
cable_num=$(echo $services | cut -d'_' -f 2)
device_str="ethernet_${cable_num}_cable"
ssh root@${OLD_IPADDR} "connmanctl config ${device_str} --ipv4 manual ${NEW_IPADDR} 255.255.255.0 192.168.3.1;"
echo ""
echo "-------------------------------------------------------------------------"
