#!/bin/sh

echo "Running Power On Self Test (POST):"

if [ ! -e /etc/celltype ]; then
   # There's no fdl. Either something went wrong during the NorCal init
   # stage, or we're in manufacturing and the scd/fdl hasn't been
   # programmed. Skip POST.
   echo "System was not initialized. Aborting."
   exit 1
fi

grep 'supervisor' /etc/celltype >> /dev/null
SUPERVISOR=$?
grep 'fixed' /etc/celltype >> /dev/null
FIXED=$?

if [ $FIXED -eq 0 ]; then
   # We're on a fixed system.
   
   # Led testing
   echo -n "Testing LEDs: "
   # Put leds into diag mode
   led mode diagnostic
   # Set the status led to continue flashing green during POST
   led set --green --device Status --flash 1 --ramp 0
   # Turn all leds yellow / red
   led set --red --device Ethernet --device Fan --device PowerSupply --index all --ramp 0
   # Wait 2 seconds
   sleep 2
   # Turn all port leds off
   led set --device Ethernet --device Fan --device PowerSupply --index all --ramp 0
   # Wait 0.75 second
   sleep 0.75
   # Turn all port leds green
   led set --green --device Ethernet --device Fan --device PowerSupply --index all --ramp 0
   # wait 2 seconds
   sleep 2
   # Turn all port leds off
   led set --device Ethernet --device Fan --device PowerSupply --index all --ramp 0
   # Return control of the leds to the system
   led mode normal
fi

echo "Finished Power On Self Test (POST): PASSED"
exit 0
