I use this script in Mac OS X to handle some startup actions that I need automated. What do you think of the script? It runs well, but would you do it this way or another way?
Code:
# startup_actions (Automator action-"Run Shell Script")
# Set appropriate PATH variable
export PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
# Wait 3 seconds for WiFi to come up
sleep 3
# Variable declarations
LOCAL_IP_TEST=192.168
LOCAL_IP=192.168.2.4
EXT_IP=67.84.74.65
TEST_SITE=www.google.com
MOUNT_PT=/Volumes/starbox_ninjasb
count=3
if [ 'ping -c $count "$TEST_SITE"' ] # Test for network connection
then
# Create mount point if necessary
if [ ! -e "$MOUNT_PT" ]
then
mkdir "$MOUNT_PT"
fi
# Mount /home/ninjasb@starbox via sshfs
if ifconfig | grep "$LOCAL_IP_TEST" > /dev/null # Test connection type for local or ext
then
sshfs ninjasb@"$LOCAL_IP":/home/ninjasb "$MOUNT_PT" -oreconnect,volname=starbox_ninjasb
else
sshfs ninjasb@"$EXT_IP":/home/ninjasb "$MOUNT_PT" -oreconnect,volname=starbox_ninjasb
fi
# Start mpd if it isn't already running
if [ -z $(pidof mpd) ]
then
sleep 1; mpd # Wait for sshfs mount to settle, then run mpd
fi
else
exit 0 # Fail-no internet connection
fi