#!/bin/bash

if [ ! "$UID" -eq 0 ] ; then
        echo "The cell modem can only be powered as root or sudo."
        exit -1
fi

GPIO=gpio38

delay_five()
{
    SECS=0
    while [[ $SECS != 5 ]] ; do
        echo -n "."
        sleep 1
        SECS=$(($SECS+1))
    done
    echo ""
}

if [ "$#" -eq 0 ] ; then
        echo "Usage:  power-cell-modem [on | off]"
        exit 1
elif [ "$1" == "on" ] ; then
        echo -n "Restoring power to the cell modem."
        echo 1 > /sys/class/gpio/$GPIO/value
        delay_five
        echo -n "Re-enabling the cell modem."
        enable-cell-modem on
        delay_five
        echo "Done."
elif [ "$1" == "off" ] ; then
        echo -n "Disabling the cell modem."
        enable-cell-modem off
        delay_five
        echo -n "Powering off the cell modem."
        echo 0 > /sys/class/gpio/$GPIO/value
        delay_five
fi


exit 0



