#!/bin/sh

source /usr/bin/qiba-leds.sh

TEST_STATUS=$(/usr/bin/qiba-spi-get-production-info.sh -t)

if [ "$TEST_STATUS" = "2" ]; then
    if [ -s /mnt/data/local/config/network ]; then
        /usr/bin/qiba-spi-set-production-info.sh -t 3

        led1_set_blink green 100 100
        led2_set_blink green 100 100

        echo "Running speaker test ..."
        /usr/bin/qiba-speaker-test.sh
        exit 1
    else
        led1_set_blink red 100 100
        led2_set_blink red 100 100
        echo "Playing white noise to announce error ..."
        /usr/bin/speaker-test >/dev/null
        exit 1
    fi
elif [ "$TEST_STATUS" = "3" ]; then
    exit 0
else
    led1_set_blink red 100 100
    led2_set_blink red 100 100
    echo "Playing white noise to announce error ..."
    /usr/bin/speaker-test >/dev/null
    exit 1
fi
