#! /bin/bash# Copyright 1999-2004 Gentoo Foundation# Distributed under the terms of the GNU General Public License v2# $Header: /var/cvsroot/gentoo-x86/sys-power/acpid/files/acpid-1.0.4-default.sh,v 1.1 2005/03/15 19:15:53 ciaranm Exp $# Default acpi script that takes an entry for all actions# Hacked by Jaco Kroon <jaco@kroon.co.za>group=${1/\/*/}action=${1/*\//}acpi_dev=${2}event_code=${3}seq_number=${4}logger "ACPI group='${group}', action='${action}', dev=${acpi_dev}, ev=${event_code}, num=${seq_number}"function allusers() { scriptname="${1}" shift while [[ $# != 0 ]]; do params=" '${1}'" shift done echo "${scriptname}${params}" for u in $(who | awk '{ print $1 }' | sort -u); do uhome=$(getent passwd ${u} | awk -F: '{ print $6 }') logfile="${uhome}/.acpi/log" if [ -x "${uhome}/.acpi/${scriptname}" ]; then# logger "Executing ${scriptname} for ${u}" echo "==== $(date '+%Y-%m-%d %H:%M:%S'): ${scriptname}${params} ====" >> ${logfile} su - "$u" -c "'${uhome}/.acpi/${scriptname}'${params}" 2>&1 >> "${logfile}" fi done}case "$group" in button) case "$action" in power) allusers power [ ! -f /var/lock/acpi_power ] && /sbin/init 0 ;; lid) state=$(awk '{ print $2 }' < /proc/acpi/button/lid/LID/state) logger "Lid is now $state" allusers lid $state # Suspend to RAM if the system is idle. Note that if the system # just happens to be overly busy over the last minute (user scripts above?) # then this may fail. So possibly drop the minute check and only look # at the 5-minute period or change it so that if either of them is < 0.1 [ "$state" == "closed" ] && \ uptime | sed -r -e 's/^.*average: (.*), (.*), (.*)$/\1 \2 \3/' \ | awk '{ if($1 < 0.1 && $2 < 0.2) system("/usr/local/sbin/restabit --mem"); }' ;; *) logger "ACPI button/$action is not defined" ;; esac ;; *) logger "ACPI group $group / action $action is not defined" ;;esac