1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#!/bin/bash
###########################################################################
# #
# Powersave Daemon #
# #
# Copyright (C) 2004,2005 SUSE Linux Products GmbH #
# #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the #
# Free Software Foundation; either version 2 of the License, or (at you #
# option) any later version. #
# #
# This program is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., #
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #
# #
###########################################################################
#
# notify users about more or less critical events. This script only displays non-graphical
# notifications. do_x_notification cares about graphical ones.
# called with one argument (can not be set via configuration ATM), displays the argument.
# called with 2 arguments is a bit magic:
# - 2nd argument is "ERROR", "WARN" or "INFO": determines the emergency
# - nothing of the above: current scheme -> display the current powersaved event.
# the 2nd argument handling is a bit ugly. Compatibility....
. "${0%/*}/helper_functions"
# we already log this at DIAG level in helper_functions
DEBUG "process script: notify" INFO
#######################################################################
# process arguments:
MESSAGE="";LEVEL="INFO"
# invoked from script
if [ -n "$1" -a \( -z "$3" -o "$3" == CONTINUE \) ]; then
MESSAGE="`echo $1`"
LEVEL="$2"
fi
# invoked from daemon, e.g. "EVENT_BUTTON_POWER=notify"
if [ -z "$MESSAGE" ]; then
MESSAGE="Powersaved event: ${EVENT_TYPE}${EVENT_SUBTYPE:+" $EVENT_SUBTYPE"}${EVENT_EXT:+" $EVENT_EXT"}"
fi
for x in ${NOTIFY_METHOD:-notify_popup_fallback notify_acoustic}; do
[ -x $ZENITY_BIN ] && ZENITY=true || ZENITY=false
case "$x" in
notify_popup_window|notify_popup_fallback)
$SCRIPT_RETURN $EV_ID 2 "$MESSAGE"
;;
notify_console)
echo "$MESSAGE" | fmt |wall
;;
notify_acoustic)
( for y in . . . ; do
echo -en "\007" > /dev/tty0
usleep 500000
done ) &
;;
none) # do nothing
;;
*)
DEBUG "Wrong value $x in $SYSCONF_DIR common for variable NOTIFY_METHOD" ERROR
;;
esac
done
if [ "$3" != CONTINUE ]; then
$SCRIPT_RETURN $EV_ID 0 "notify finished"
fi
EXIT 0
|