#!/bin/sh
##############################################################################
#
#  Copyright (c) 2008, Doremi Labs, Inc.
#    All rights reserved.
#
#  Redistribution in source or binary forms, with or without
#  modification, are NOT permitted.
#
#    Doremi Labs, Inc.
#    306 East Alameda Avenue
#    Burbank, CA 91502
#    Tel : (818) 562 1101
#    Fax : (818) 562 1109
#
#
##############################################################################

POPUP=/doremi/X11R6/bin/drmpopup.out
LANGCF=/doremi/etc/language
APCACCESS=/sbin/apcaccess
TIMELEFT="unknown"
BCHARGE="unknown"

test -x ${POPUP} || exit 0

if test -x ${APCACCESS}; then
  TEMP1=`${APCACCESS} | grep BCHARGE | cut -d: -f2 | sed -e 's/[ 0]*//' | cut -d. -f1`
  if test -n "${TEMP1}"; then
    BCHARGE="${TEMP1}"
  fi
  TEMP2=`${APCACCESS} | grep TIMELEFT | cut -d: -f2`
  if test -n "${TEMP2}"; then
    TIMELEFT="${TEMP2}"
  fi
fi

TITLE="Warning: power loss detected"
MESSAGE="Power failure. The system is now running on battery.<br>Battery charge is: ${BCHARGE}%.<br>Estimated time left is: ${TIMELEFT}."

# translations
if grep -qs fr-FR ${LANGCF}; then
TITLE="Attention: panne d'alimentation detectee"
MESSAGE="Panne d'alimentation electrique. Le systme fonctionne maintenant sur batterie.<br>La charge de la batterie est: ${BCHARGE}%.<br>Le temps restant estim: ${TIMELEFT}."
fi

${POPUP} "${TITLE}" "<b>`date +'%a %b %-d, %Y ; %H:%M'`</b><br><br>${MESSAGE}" --warning

exit 0
