#!/bin/sh
# $Id: whereami.apm,v 1.5 2002/01/16 09:07:07 andrew Exp $
# This script will run whereami on suspend and resume of the machine.
# If you have logger installed, whereami output will be sent to syslog.
#
# On suspend/resume, whereami will change to the location specified in
# the config file for SUSPEND_LOCATION and RESUME_LOCATION.
# If the location is 'auto', whereami performs location detection.
#
# For example:
# SUSPEND_LOCATION=disconnected
# RESUME_LOCATION=auto

WHEREAMI=/usr/sbin/whereami
CONFIG=/etc/whereami/apm.conf

[ -r $CONFIG ] || exit 0
[ -x $WHEREAMI ] || exit 0

. $CONFIG

case "$1" in
suspend)
	LOCATION=$SUSPEND_LOCATION
	;;
resume)
	LOCATION=$RESUME_LOCATION
	;;
esac

[ -n "$LOCATION" ] || exit 0

[ "$LOCATION" = "auto" ] && LOCATION=

# Find actual whereami
ACTUAL_WHEREAMI=`readlink /usr/sbin/whereami`

if [ "$ACTUAL_WHEREAMI" = "/usr/sbin/whereami.sh" ]; then
  # The old shell script took no parameters
  $WHEREAMI $LOCATION
else
  # Use new format
  if [ -x /usr/bin/logger ] ; then
    logger -t whereami.apm "Running whereami $LOCATION"
    $WHEREAMI --run_from apm --syslog $LOCATION | logger -t whereami
  else
    $WHEREAMI --run_from apm --syslog $LOCATION
  fi
fi

