#!/bin/bash

PORT=$1
DEVICE=$2

# Full provisioning of a device, with ssh demonstration
# Most of this can actually be achieved by running flash-image, but
# this is a more robust method of provisioning devices.

echo "Mass-storage device"
rpi-power-hat mass-storage $PORT $DEVICE
sleep 5
echo "Flashing image"
rpi-power-hat flash-image $PORT latest
sleep 2
echo "Turning off device"
rpi-power-hat set $PORT 0
sleep 2
echo "Turning on device"
rpi-power-hat set $PORT 1
echo "Waiting 120s for device to boot"
sleep 120
echo "SSH into device"
rpi-power-hat ssh $PORT
echo "Success"

