#!/bin/sh

# reset paths
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:~/bin

# configure the power use settings
sudo ConfigurePower

# initialize the power switches (turns them all off, use
# SetPowerSwitch to set individual switches)
sudo InitPowerSwitches

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:~/bin
export LD_LIBRARY_PATH=/usr/local/lib:~/lib

(
        while true
        do
                echo ""
                echo "==================="
                echo "Starting SMC (wait)"
                echo "==================="
                echo ""

                sudo EncryptedStartup
                rv="$?"

                ps -e | grep omniNames > /dev/null

                if [ "$?" -eq 0 ]
                then
                        echo "SMC software launched, smc0 user exiting"
                        exit 0
                fi

                echo ""
                echo "SMC exited with code $rv"
                sleep 30
        done
) &
