#!/bin/bash

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 <device_id>"
  exit 1
fi

device_id="$1"

export ADB_VENDOR_KEYS="./adbkey"
echo ADB=$ADB_VENDOR_KEYS

ip=$1
adb connect $ip:5555 && adb root && adb connect $ip:5555
adb remount
mac=`adb shell getprop ro.boot.mac`
echo "DEVICEID: $(echo "$mac" | tr -d ':' | tr '[:lower:]' '[:upper:]')"
echo "------------------------------"

# Set the time zone to CDT and configure NTP server on the Android device
adb -s "$device_id" shell "setprop persist.sys.timezone America/Chicago"
#adb -s "$device_id" shell "settings put global ntp_server 10.164.29.21"
adb -s "$device_id" shell "settings put global ntp_server pool.ntp.org"

# Get the current date and time in CDT
current_date_cdt=$(TZ="America/Chicago" date +'%m%d%H%M%Y.%S')

# Send the date to the Android device
adb -s "$device_id" shell "date \"$current_date_cdt\""

# Verify that the date, time, and NTP server have been set on the device
adb -s "$device_id" shell date
adb -s "$device_id" shell "settings get global ntp_server"

adb reboot
adb disconnect
