This patchset just adds simple location independence.  It can also be
pulled from git://fnordovax.org/pm-utils/ (branch named
vlowther-simple-location-independence)

It uses automake to transform src/pm-action.in, src/pm-powersave.in,
and pm/functions.in into src/pm-action, src/pm-powersave, and
pm/functions respectivly.  See the appropriate Makefile.am files for
the details.

Location independence of the hooks is achieved by having pm-action and
pm-powersave export PM_FUNCTIONS, which points to the installed
location of pm/functions.
The hooks have been modified to source functions from that environment variable.

Comments?
From fa5cbe713ac0360ecdeb6f6dae1a12ab8ed53dbf Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 12:11:49 -0600
Subject: [PATCH] Export location of pm/functions from pm-action

---
 src/pm-action |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/pm-action b/src/pm-action
index 3a1e6a5..68dbb93 100755
--- a/src/pm-action
+++ b/src/pm-action
@@ -84,7 +84,8 @@ do
 	shift
 done
 
-. /usr/lib/pm-utils/functions
+export PM_FUNCTIONS="/usr/lib/pm-utils/functions"
+. "${PM_FUNCTIONS}"
 
 [ -f /sys/power/state ] || exit 1
 
-- 
1.5.3.8

From 7b30515881b033ed2d1e4e11f3c8b3bc5e205683 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 12:14:31 -0600
Subject: [PATCH] Update pm-powersave to export the location of pm/functions in PM_FUNCTIONS

---
 src/pm-powersave |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pm-powersave b/src/pm-powersave
index 11ec1b9..5611586 100755
--- a/src/pm-powersave
+++ b/src/pm-powersave
@@ -25,8 +25,8 @@
 #
 
 POWERSAVE_LOGFILE="/dev/null"
-[ -f /usr/lib/pm-utils/functions ] || return 1
-. /usr/lib/pm-utils/functions
+PM_FUNCTIONS="/usr/lib/pm-utils/functions"
+. "${PM_FUNCTIONS}"
 
 if [ "x$1" = "xtrue" -o "x$1" = "xfalse" ] ; then
     init_logfile "${POWERSAVE_LOGFILE}"
-- 
1.5.3.8

From ed60581bb7ff249ae9cf509c5937929af1f85c47 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 12:21:46 -0600
Subject: [PATCH] Modified hooks to source $PM_FUNCTIONS instead of /usr/lib/pm-utils/functions

---
 pm/sleep.d/00clear          |    2 +-
 pm/sleep.d/00logging        |    2 +-
 pm/sleep.d/10NetworkManager |    2 +-
 pm/sleep.d/20video          |    2 +-
 pm/sleep.d/49bluetooth      |    2 +-
 pm/sleep.d/50modules        |    2 +-
 pm/sleep.d/55battery        |    2 +-
 pm/sleep.d/65alsa           |    2 +-
 pm/sleep.d/90clock          |    2 +-
 pm/sleep.d/94cpufreq        |    2 +-
 pm/sleep.d/99video          |    2 +-
 pm/sleep.d/zzz              |    2 +-
 12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/pm/sleep.d/00clear b/pm/sleep.d/00clear
index b96e0a7..b6260bd 100755
--- a/pm/sleep.d/00clear
+++ b/pm/sleep.d/00clear
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 RETVAL=0
 case "$1" in
diff --git a/pm/sleep.d/00logging b/pm/sleep.d/00logging
index 61285fe..7cba5e7 100755
--- a/pm/sleep.d/00logging
+++ b/pm/sleep.d/00logging
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 case "$1" in
         hibernate|suspend)
diff --git a/pm/sleep.d/10NetworkManager b/pm/sleep.d/10NetworkManager
index 3e018ec..d1ad677 100755
--- a/pm/sleep.d/10NetworkManager
+++ b/pm/sleep.d/10NetworkManager
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 command_exists dbus-send || exit 1
 
diff --git a/pm/sleep.d/20video b/pm/sleep.d/20video
index 1beee57..faed5a9 100755
--- a/pm/sleep.d/20video
+++ b/pm/sleep.d/20video
@@ -7,7 +7,7 @@
 # it under the terms of version 2 of the GNU General Public License as
 # published by the Free Software Foundation.
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 if ! command_exists vbetool; then
 	vbe() { echo "vbetool not found" 1>&2; return 1; }
diff --git a/pm/sleep.d/49bluetooth b/pm/sleep.d/49bluetooth
index bab680a..0c72b8f 100755
--- a/pm/sleep.d/49bluetooth
+++ b/pm/sleep.d/49bluetooth
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 [ -f /proc/acpi/ibm/bluetooth ] || exit 1
 
diff --git a/pm/sleep.d/50modules b/pm/sleep.d/50modules
index 19707c1..946bcee 100755
--- a/pm/sleep.d/50modules
+++ b/pm/sleep.d/50modules
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 suspend_modules()
 {
diff --git a/pm/sleep.d/55battery b/pm/sleep.d/55battery
index e5f3758..ec24ebe 100755
--- a/pm/sleep.d/55battery
+++ b/pm/sleep.d/55battery
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 resume_batteries()
 {
diff --git a/pm/sleep.d/65alsa b/pm/sleep.d/65alsa
index 0762436..35da00d 100755
--- a/pm/sleep.d/65alsa
+++ b/pm/sleep.d/65alsa
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 command_exists alsactl || exit 1
 
diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock
index 6e73714..34df62e 100755
--- a/pm/sleep.d/90clock
+++ b/pm/sleep.d/90clock
@@ -1,5 +1,5 @@
 #!/bin/sh
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 NTPD_LOCK="/var/run/pm-utils/pm-ntpd.lock"
 
diff --git a/pm/sleep.d/94cpufreq b/pm/sleep.d/94cpufreq
index 165d671..a3db064 100755
--- a/pm/sleep.d/94cpufreq
+++ b/pm/sleep.d/94cpufreq
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 
 [ -d /sys/devices/system/cpu/ ] || exit 1
diff --git a/pm/sleep.d/99video b/pm/sleep.d/99video
index 5a850ec..4bfdf83 100755
--- a/pm/sleep.d/99video
+++ b/pm/sleep.d/99video
@@ -7,7 +7,7 @@
 # it under the terms of version 2 of the GNU General Public License as
 # published by the Free Software Foundation.
 
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 
 reset_brightness() {
 	for bl in /sys/class/backlight/* ; do
diff --git a/pm/sleep.d/zzz b/pm/sleep.d/zzz
index a7ae472..202e3a0 100755
--- a/pm/sleep.d/zzz
+++ b/pm/sleep.d/zzz
@@ -1,5 +1,5 @@
 #!/bin/sh
-. /usr/lib/pm-utils/functions
+. "${PM_FUNCTIONS}"
 [ -e "${INHIBIT}" ] && return 1
 sync;sync;sync;
 case $1 in
-- 
1.5.3.8

From 7dcff332d16522b7e5f69839b279576b70b5a0f0 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 09:34:29 -0600
Subject: [PATCH] Added support for transforming .in files in pm/Makefile.am

---
 pm/Makefile.am |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/pm/Makefile.am b/pm/Makefile.am
index a063dbb..9b13c34 100644
--- a/pm/Makefile.am
+++ b/pm/Makefile.am
@@ -12,5 +12,14 @@ EXTRA_DIST =			\
 install-exec-local:
 	-mkdir $(DESTDIR)$(sysconfdir)/pm/config.d
 
+do_subst = sed -e 's,[EMAIL PROTECTED]@],$(extradir),g' \
+	   -e 's,[EMAIL PROTECTED]@],$(sysconfdir),g'
+
+SUFFIXES = .in
+
+.in:
+	$(do_subst) $< >$@
+	chmod +x $@
+
 clean-local :
 	rm -f *~
-- 
1.5.3.8

From a50dc9e1dd0b267cbc67eb34913d2f427a618671 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 09:47:39 -0600
Subject: [PATCH] Rename functions in preperation for autotools based location independence

---
 pm/functions    |  290 -------------------------------------------------------
 pm/functions.in |  290 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 290 insertions(+), 290 deletions(-)
 delete mode 100755 pm/functions
 create mode 100755 pm/functions.in

diff --git a/pm/functions b/pm/functions
deleted file mode 100755
index 76aafd1..0000000
--- a/pm/functions
+++ /dev/null
@@ -1,290 +0,0 @@
-#!/bin/sh
-# vim:noexpandtab
-
-export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/pm-utils/bin
-
-# Default values go here.  It is important to _not_ initialize some
-# variables here.  They are:
-#
-# PM_CMDLINE
-# RESUME_MODULES
-#
-set -a
-HIBERNATE_MODE="platform"
-HIBERNATE_RESUME_POST_VIDEO=no
-INHIBIT=/var/run/pm-utils.inhibit
-PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
-SUSPEND_MODULES=""
-TEMPORARY_CPUFREQ_GOVERNOR="performance"
-LOCK="/var/run/pm-utils/lock"
-STORAGEDIR="/var/run/pm-utils/storage"
-
-# Use c sort order
-export LC_COLLATE=C
-
-[ -f /usr/lib/pm-utils/defaults ] && . /usr/lib/pm-utils/defaults
-set +a
-
-
-source_configs()
-{
-	for cfg in /etc/pm/config.d/*[!~] ; do
-		[ -f "$cfg" ] || continue
-		set -a
-		. "${cfg}"
-		set +a
-	done
-}
-
-source_configs
-
-# try to take the lock.  Fail if we cannot get it.
-try_lock()
-{
-	# $1 = file to use as lockfile
-	# $2 (optional) content to write to the lockfile,
-	#               extra newline will be appended
-	# make sure the directory where the lockfile should be exists
-	mkdir -p ${1%/*}
-	# we use noclobber to make sure there are no race conditions
-	(set -o noclobber; echo "${2}" > "${1}") 2> /dev/null || return 1
-	return 0
-}
-
-# spin waiting for the lock with optional timeout.  
-# return once we have it, or the timeout has expired
-spin_lock()
-{
-	# $1 = lockfile
-	# $2 = optional timeout
-	local elapsed=0
-	while ! try_lock $1; do
-		[ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 1
-		elapsed=$(($elapsed + 1))
-		sleep 1;
-	done
-}
-
-# release the lock
-release_lock()
-{
-	# $1 = lockfile
-	# make sure it is ours first.
-	rm -rf "$1"
-	return $?
-}
-
-
-take_suspend_lock()
-{
-	VT=$(fgconsole)
-	chvt 63
-	try_lock "$LOCK" || return 1
-	mkdir -p "${STORAGEDIR}"
-	return 0
-}
-
-remove_suspend_lock()
-{
-	rm -rf "${STORAGEDIR}"
-	chvt 1
-	chvt $VT
-	release_lock "${LOCK}"
-}
-
-
-command_exists()
-{
-	# $1 = command to test for.  It can be an executable in the path,
-	# a shell function, or a shell builtin.
-	type "$1" >/dev/null 2>&1
-	return $?
-}
-
-find_hooks() {
-	# $1 = type of hook to find.  
-	# Currently only power and sleep are meaningful.
-	local syshooks="/etc/pm/$1.d"
-	local phooks="/usr/lib/pm-utils/$1.d"
-	local base
-
-	for base in $(for f in $syshooks/*[!~] $phooks/*[!~];
-		do [ -f "$f" ] && echo ${f##*/} ; done | sort | uniq) ;
-	do
-		if [ -x "$syshooks/$base" ]; then
-			echo $syshooks/$base
-		elif [ -x "$phooks/$base" ]; then
-			echo $phooks/$base
-		fi
-	done
-}
-
-run_hooks() {
-	# $1 = hooks to run
-	# $2 = parameters to pass to hooks
-	# $3 = if $3 = "reverse", then also run the hooks that ran sucessfully
-	#      backwards with parameters in $4
-        # $4 = parameters to pass to scripts when running backwards	
-	echo "$(date): running $1 hooks."
-	local hooks="$1"
-	local params="$2"
-	shift; shift
-	local revhooks
-	local file
-	for file in $(find_hooks "${hooks}"); do
-		echo "===== $(date): running hook: $file $params ====="
-		"$file" $params && revhooks="${file}${revhooks:+" ${revhooks}"}"
-	done
-	echo "$(date): done running $hooks:$params hooks."
-	if [ "x$1" = "xreverse" ]; then
-		echo "$(date): running $hooks hooks backwards."
-		for file in $revhooks; do
-			echo "===== $(date): running hook :$file $2 ====="
-			"${file}" $2
-		done
-		echo "$(date): done running $hooks:$2 backwards"
-	fi
-}
-
-get_power_status()
-{
-	RETVAL=0
-	on_ac_power
-	case "$?" in
-		"0")
-			echo "ac"
-			;;
-		"1")
-			echo "battery"
-			;;
-		"255")
-			echo "error"
-			RETVAL=1
-			;;
-	esac
-	return $RETVAL
-}
-
-do_suspend()
-{
-	pm-pmu --suspend || echo -n "mem" > /sys/power/state
-}
-
-do_hibernate()
-{
-	echo -n "${HIBERNATE_MODE}" > /sys/power/disk
-	echo -n "disk" > /sys/power/state
-}
-
-do_suspend_hybrid()
-{
-	return 1
-}
-
-init_logfile() {
-	if [ -n "$1" ]; then
-		exec > "$1" 2>&1
-	fi
-}
-
-pm_main()
-{
-	init_logfile "$PM_LOGFILE" 
-	take_suspend_lock || exit 1
-
-	# make sure that our locks are unlocked no matter how the script exits
-	trap remove_suspend_lock 0
-
-	rm -f "$INHIBIT"
-
-	run_hooks sleep "$1" reverse "$2"
-
-	return 0
-}
-
-_rmmod() {
-	if modprobe -r $1; then
-		touch "${STORAGEDIR}/module:$1"
-		return 0
-	else
-		echo "# could not unload '$1', usage count was $2"
-		return 1
-	fi
-}
-
-# this recursively unloads the given modules and all that depend on it
-# first parameter is the module to be unloaded
-modunload()
-{
-	local MOD D C USED MODS I
-	local UNL="$(echo $1 |tr - _)" RET=1 
-
-	while read MOD D C USED D; do
-		[ "$MOD" = "$UNL" ] || continue
-		if [ "$USED" = "-" ]; then
-			# no dependent modules, just try to remove this one.
-			_rmmod "$MOD" $C
-			RET=$?
-		else
-			# modules depend on this one.  try to remove them first.
-			MODS="${USED%%*,}"
-			while [ "${MODS}" ]; do
-				# try to unload the last one first
-				MOD="${MODS##*,}"
-				modunload $MOD && RET=0
-				# prune the last one from the list
-				MODS="${MODS%,*}"
-			done
-			# if we unloaded at least one module, then let's
-			# try again!
-			[ $RET -eq 0 ] && modunload $MOD
-			RET=$?
-		fi
-		return $RET
-	done < /proc/modules
-	# if we came this far, there was nothing to do, 
-	# the module is no longer loaded.
-	return 0
-}
-
-# reload all the modules in no particular order.
-modreload()
-{
-	for x in ${STORAGEDIR}/module:* ; do
-		[ -f "${x}" ] && modprobe "${x##*:}" >/dev/null 2>&1
-	done
-}
-
-if ! command_exists service; then
-	service() {
-		if [ -x "/etc/init.d/$1" ]; then
-			"/etc/init.d/$@"
-		else
-			echo "$1" $": unrecognized service" 1>&2
-			return 1
-		fi
-	}
-fi
-
-stopservice()
-{
-	if service "$1" status 2>/dev/null | grep -c -q running; then
-		touch "${STORAGEDIR}/service:$1"
-		service "$1" stop
-	fi
-}
-
-restartservice()
-{
-	[ -f "${STORAGEDIR}/service:$1" ] && service "$1" start
-}
-
-savestate()
-{
-	echo "$2" > "${STORAGEDIR}/state:$1"
-}
-
-restorestate()
-{
-	cat "${STORAGEDIR}/state:${1}"
-}
diff --git a/pm/functions.in b/pm/functions.in
new file mode 100755
index 0000000..76aafd1
--- /dev/null
+++ b/pm/functions.in
@@ -0,0 +1,290 @@
+#!/bin/sh
+# vim:noexpandtab
+
+export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/pm-utils/bin
+
+# Default values go here.  It is important to _not_ initialize some
+# variables here.  They are:
+#
+# PM_CMDLINE
+# RESUME_MODULES
+#
+set -a
+HIBERNATE_MODE="platform"
+HIBERNATE_RESUME_POST_VIDEO=no
+INHIBIT=/var/run/pm-utils.inhibit
+PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
+SUSPEND_MODULES=""
+TEMPORARY_CPUFREQ_GOVERNOR="performance"
+LOCK="/var/run/pm-utils/lock"
+STORAGEDIR="/var/run/pm-utils/storage"
+
+# Use c sort order
+export LC_COLLATE=C
+
+[ -f /usr/lib/pm-utils/defaults ] && . /usr/lib/pm-utils/defaults
+set +a
+
+
+source_configs()
+{
+	for cfg in /etc/pm/config.d/*[!~] ; do
+		[ -f "$cfg" ] || continue
+		set -a
+		. "${cfg}"
+		set +a
+	done
+}
+
+source_configs
+
+# try to take the lock.  Fail if we cannot get it.
+try_lock()
+{
+	# $1 = file to use as lockfile
+	# $2 (optional) content to write to the lockfile,
+	#               extra newline will be appended
+	# make sure the directory where the lockfile should be exists
+	mkdir -p ${1%/*}
+	# we use noclobber to make sure there are no race conditions
+	(set -o noclobber; echo "${2}" > "${1}") 2> /dev/null || return 1
+	return 0
+}
+
+# spin waiting for the lock with optional timeout.  
+# return once we have it, or the timeout has expired
+spin_lock()
+{
+	# $1 = lockfile
+	# $2 = optional timeout
+	local elapsed=0
+	while ! try_lock $1; do
+		[ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 1
+		elapsed=$(($elapsed + 1))
+		sleep 1;
+	done
+}
+
+# release the lock
+release_lock()
+{
+	# $1 = lockfile
+	# make sure it is ours first.
+	rm -rf "$1"
+	return $?
+}
+
+
+take_suspend_lock()
+{
+	VT=$(fgconsole)
+	chvt 63
+	try_lock "$LOCK" || return 1
+	mkdir -p "${STORAGEDIR}"
+	return 0
+}
+
+remove_suspend_lock()
+{
+	rm -rf "${STORAGEDIR}"
+	chvt 1
+	chvt $VT
+	release_lock "${LOCK}"
+}
+
+
+command_exists()
+{
+	# $1 = command to test for.  It can be an executable in the path,
+	# a shell function, or a shell builtin.
+	type "$1" >/dev/null 2>&1
+	return $?
+}
+
+find_hooks() {
+	# $1 = type of hook to find.  
+	# Currently only power and sleep are meaningful.
+	local syshooks="/etc/pm/$1.d"
+	local phooks="/usr/lib/pm-utils/$1.d"
+	local base
+
+	for base in $(for f in $syshooks/*[!~] $phooks/*[!~];
+		do [ -f "$f" ] && echo ${f##*/} ; done | sort | uniq) ;
+	do
+		if [ -x "$syshooks/$base" ]; then
+			echo $syshooks/$base
+		elif [ -x "$phooks/$base" ]; then
+			echo $phooks/$base
+		fi
+	done
+}
+
+run_hooks() {
+	# $1 = hooks to run
+	# $2 = parameters to pass to hooks
+	# $3 = if $3 = "reverse", then also run the hooks that ran sucessfully
+	#      backwards with parameters in $4
+        # $4 = parameters to pass to scripts when running backwards	
+	echo "$(date): running $1 hooks."
+	local hooks="$1"
+	local params="$2"
+	shift; shift
+	local revhooks
+	local file
+	for file in $(find_hooks "${hooks}"); do
+		echo "===== $(date): running hook: $file $params ====="
+		"$file" $params && revhooks="${file}${revhooks:+" ${revhooks}"}"
+	done
+	echo "$(date): done running $hooks:$params hooks."
+	if [ "x$1" = "xreverse" ]; then
+		echo "$(date): running $hooks hooks backwards."
+		for file in $revhooks; do
+			echo "===== $(date): running hook :$file $2 ====="
+			"${file}" $2
+		done
+		echo "$(date): done running $hooks:$2 backwards"
+	fi
+}
+
+get_power_status()
+{
+	RETVAL=0
+	on_ac_power
+	case "$?" in
+		"0")
+			echo "ac"
+			;;
+		"1")
+			echo "battery"
+			;;
+		"255")
+			echo "error"
+			RETVAL=1
+			;;
+	esac
+	return $RETVAL
+}
+
+do_suspend()
+{
+	pm-pmu --suspend || echo -n "mem" > /sys/power/state
+}
+
+do_hibernate()
+{
+	echo -n "${HIBERNATE_MODE}" > /sys/power/disk
+	echo -n "disk" > /sys/power/state
+}
+
+do_suspend_hybrid()
+{
+	return 1
+}
+
+init_logfile() {
+	if [ -n "$1" ]; then
+		exec > "$1" 2>&1
+	fi
+}
+
+pm_main()
+{
+	init_logfile "$PM_LOGFILE" 
+	take_suspend_lock || exit 1
+
+	# make sure that our locks are unlocked no matter how the script exits
+	trap remove_suspend_lock 0
+
+	rm -f "$INHIBIT"
+
+	run_hooks sleep "$1" reverse "$2"
+
+	return 0
+}
+
+_rmmod() {
+	if modprobe -r $1; then
+		touch "${STORAGEDIR}/module:$1"
+		return 0
+	else
+		echo "# could not unload '$1', usage count was $2"
+		return 1
+	fi
+}
+
+# this recursively unloads the given modules and all that depend on it
+# first parameter is the module to be unloaded
+modunload()
+{
+	local MOD D C USED MODS I
+	local UNL="$(echo $1 |tr - _)" RET=1 
+
+	while read MOD D C USED D; do
+		[ "$MOD" = "$UNL" ] || continue
+		if [ "$USED" = "-" ]; then
+			# no dependent modules, just try to remove this one.
+			_rmmod "$MOD" $C
+			RET=$?
+		else
+			# modules depend on this one.  try to remove them first.
+			MODS="${USED%%*,}"
+			while [ "${MODS}" ]; do
+				# try to unload the last one first
+				MOD="${MODS##*,}"
+				modunload $MOD && RET=0
+				# prune the last one from the list
+				MODS="${MODS%,*}"
+			done
+			# if we unloaded at least one module, then let's
+			# try again!
+			[ $RET -eq 0 ] && modunload $MOD
+			RET=$?
+		fi
+		return $RET
+	done < /proc/modules
+	# if we came this far, there was nothing to do, 
+	# the module is no longer loaded.
+	return 0
+}
+
+# reload all the modules in no particular order.
+modreload()
+{
+	for x in ${STORAGEDIR}/module:* ; do
+		[ -f "${x}" ] && modprobe "${x##*:}" >/dev/null 2>&1
+	done
+}
+
+if ! command_exists service; then
+	service() {
+		if [ -x "/etc/init.d/$1" ]; then
+			"/etc/init.d/$@"
+		else
+			echo "$1" $": unrecognized service" 1>&2
+			return 1
+		fi
+	}
+fi
+
+stopservice()
+{
+	if service "$1" status 2>/dev/null | grep -c -q running; then
+		touch "${STORAGEDIR}/service:$1"
+		service "$1" stop
+	fi
+}
+
+restartservice()
+{
+	[ -f "${STORAGEDIR}/service:$1" ] && service "$1" start
+}
+
+savestate()
+{
+	echo "$2" > "${STORAGEDIR}/state:$1"
+}
+
+restorestate()
+{
+	cat "${STORAGEDIR}/state:${1}"
+}
-- 
1.5.3.8

From 349c2e5a0c7ab1c81be31eeae2d633935d1823a2 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 12:39:57 -0600
Subject: [PATCH] Use autotools to make functions location-independent.

---
 pm/Makefile.am  |    5 ++++-
 pm/functions.in |   10 +++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/pm/Makefile.am b/pm/Makefile.am
index 9b13c34..e064ac0 100644
--- a/pm/Makefile.am
+++ b/pm/Makefile.am
@@ -1,11 +1,14 @@
 SUBDIRS =  sleep.d power.d
 
 extradir = $(libdir)/pm-utils
+pm_sysconfdir = $(sysconfdir)/pm
 
 extra_SCRIPTS =			\
 	functions		\
 	defaults
 
+CLEANFILES = functions
+
 EXTRA_DIST =			\
 	$(extra_SCRIPTS)
 
@@ -13,7 +16,7 @@ install-exec-local:
 	-mkdir $(DESTDIR)$(sysconfdir)/pm/config.d
 
 do_subst = sed -e 's,[EMAIL PROTECTED]@],$(extradir),g' \
-	   -e 's,[EMAIL PROTECTED]@],$(sysconfdir),g'
+	   -e 's,[EMAIL PROTECTED]@],$(pm_sysconfdir),g'
 
 SUFFIXES = .in
 
diff --git a/pm/functions.in b/pm/functions.in
index 76aafd1..3cb3f19 100755
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -1,7 +1,7 @@
 #!/bin/sh
 # vim:noexpandtab
 
-export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/pm-utils/bin
+export PATH=/sbin:/usr/sbin:/bin:/usr/bin:@PM-UTILS-LIBDIR@/bin
 
 # Default values go here.  It is important to _not_ initialize some
 # variables here.  They are:
@@ -22,13 +22,13 @@ STORAGEDIR="/var/run/pm-utils/storage"
 # Use c sort order
 export LC_COLLATE=C
 
-[ -f /usr/lib/pm-utils/defaults ] && . /usr/lib/pm-utils/defaults
+[ -f @PM-UTILS-LIBDIR@/defaults ] && . @PM-UTILS-LIBDIR@/defaults
 set +a
 
 
 source_configs()
 {
-	for cfg in /etc/pm/config.d/*[!~] ; do
+	for cfg in @PM-UTILS-SYSCONFDIR@/config.d/*[!~] ; do
 		[ -f "$cfg" ] || continue
 		set -a
 		. "${cfg}"
@@ -104,8 +104,8 @@ command_exists()
 find_hooks() {
 	# $1 = type of hook to find.  
 	# Currently only power and sleep are meaningful.
-	local syshooks="/etc/pm/$1.d"
-	local phooks="/usr/lib/pm-utils/$1.d"
+	local syshooks="@PM-UTILS-SYSCONFDIR@/$1.d"
+	local phooks="@PM-UTILS-LIBDIR@/$1.d"
 	local base
 
 	for base in $(for f in $syshooks/*[!~] $phooks/*[!~];
-- 
1.5.3.8

From eb9e9de8b93c03a554461f0d1eeea1dba0c78f97 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 10:06:24 -0600
Subject: [PATCH] Modify src/Makefile.am in preperation for making the pm-action scripts
 location independent.

---
 src/Makefile.am |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 184c221..8dce4db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,6 @@
-pm_utils_bindir = $(libdir)/pm-utils/bin
+pm_utils_libdir = $(libdir)/pm-utils
+pm_utils_bindir = $(pm_utils_libdir)/bin
+pm_sysconfdir = $(sysconfdir)/pm
 
 pm_utils_bin_PROGRAMS =		\
 	pm-pmu			\
@@ -28,7 +30,16 @@ acpowerdir = $(bindir)
 acpower_SCRIPTS =		\
 	on_ac_power
 
-install-exec-hook:
+do_subst = sed -e 's,[EMAIL PROTECTED]@],$(pm_utils_libdir),g' \
+	   -e 's,[EMAIL PROTECTED]@],$(pm_sysconfdir),g'
+
+SUFFIXES = .in
+
+.in:
+	$(do_subst) $< >$@
+	chmod +x $@
+
+install-data-hook:
 	-mkdir -p $(DESTDIR)$(sbindir)
 	-ln -s $(pm_utils_bindir)/pm-action $(DESTDIR)$(sbindir)/pm-suspend
 	-ln -s $(pm_utils_bindir)/pm-action $(DESTDIR)$(sbindir)/pm-hibernate
-- 
1.5.3.8

From 7616c68a5aed5caf806056b6dd2d47a2f68950ad Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 10:07:29 -0600
Subject: [PATCH] Renamed pm-action in preperation for making it location independent.

---
 src/pm-action    |  126 ------------------------------------------------------
 src/pm-action.in |  126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+), 126 deletions(-)
 delete mode 100755 src/pm-action
 create mode 100755 src/pm-action.in

diff --git a/src/pm-action b/src/pm-action
deleted file mode 100755
index 68dbb93..0000000
--- a/src/pm-action
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/bin/sh
-#
-# Simple suspend script
-#
-# Copyright 2006 Red Hat, Inc.
-#
-# Based on work from:
-#    Bill Nottingham <[EMAIL PROTECTED]>
-#    Peter Jones <[EMAIL PROTECTED]>
-#    David Zeuthen <[EMAIL PROTECTED]>
-#    Richard Hughes <[EMAIL PROTECTED]>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of version 2 of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-# The rule here? Simplicity.
-
-help_options() {
-	echo "${0##*/} [options]"
-	echo
-	echo "Options can change how the supend or hibernate is done."
-	echo
-	echo "Possible actions are:"
-	echo
-	echo "  --quirk-dpms-on"
-	echo "  --quirk-dpms-suspend"
-	echo "  --quirk-radeon-off"
-	echo "  --quirk-reset-brightness"
-	echo "  --quirk-s3-bios"
-	echo "  --quirk-s3-mode"
-	echo "  --quirk-vbe-post"
-	echo "  --quirk-vbemode-restore"
-	echo "  --quirk-vbestate-restore"
-	echo "  --quirk-vga-mode3"
-	echo
-}
-
-if [ -n "$EUID" -a "$EUID" != "0" ]; then
-	echo This utility may only be run by the root user. 1>&2
-	exit 1
-fi
-
-# Get the command line options
-while [ $# -gt 0 ]
-do
-	case "$1" in
-		--quirk-dpms-on)
-			export DISPLAY_QUIRK_DPMS_ON="true" ;;
-		--quirk-dpms-suspend)
-			export DISPLAY_QUIRK_DPMS_SUSPEND="true" ;;
-		--quirk-radeon-off)
-			export DISPLAY_QUIRK_RADEON_OFF="true" ;;
-		--quirk-reset-brightness)
-			export DISPLAY_QUIRK_RESET_BRIGHTNESS="true" ;;
-		--quirk-s3-bios)
-			export DISPLAY_QUIRK_S3_BIOS="true" ;;
-		--quirk-s3-mode)
-			export DISPLAY_QUIRK_S3_MODE="true" ;;
-		--quirk-vbe-post)
-			export DISPLAY_QUIRK_VBE_POST="true" ;;
-		--quirk-vbemode-restore)
-			export DISPLAY_QUIRK_VBEMODE_RESTORE="true" ;;
-		--quirk-vbestate-restore)
-			export DISPLAY_QUIRK_VBESTATE_RESTORE="true" ;;
-		--quirk-vga-mode3)
-			export DISPLAY_QUIRK_VGA_MODE_3="true" ;;
-		--help)
-			help_options
-			exit 0 ;;
-		*)
-			break ;; # terminate while loop
-	esac
-	shift
-done
-
-export PM_FUNCTIONS="/usr/lib/pm-utils/functions"
-. "${PM_FUNCTIONS}"
-
-[ -f /sys/power/state ] || exit 1
-
-
-ACTION=${0##*pm-}
-
-case "$ACTION" in
-	suspend)
-		if ! pm-is-supported --"$ACTION" ; then
-			echo "Error: kernel cannot suspend to ram." 1>&2
-			exit 1
-		fi
-		REVERSE=resume
-		;;
-	hibernate)
-		if ! pm-is-supported --"$ACTION" ; then
-			echo "Error: kernel cannot suspend to disk." 1>&2
-			exit 1
-		fi
-		REVERSE=thaw
-		;;
-	suspend-hybrid)
-		if ! pm-is-supported --"$ACTION" ; then
-			echo "Error: hybrid suspend is not supported." 1>&2
-			exit
-		fi
-		REVERSE=resume
-		;;
-	*)
-		exit 1
-		;;
-esac
-
-export PM_CMDLINE="$@"
-
-pm_main "$(echo $ACTION | tr - _)" "$REVERSE"
-
-exit $?
diff --git a/src/pm-action.in b/src/pm-action.in
new file mode 100755
index 0000000..68dbb93
--- /dev/null
+++ b/src/pm-action.in
@@ -0,0 +1,126 @@
+#!/bin/sh
+#
+# Simple suspend script
+#
+# Copyright 2006 Red Hat, Inc.
+#
+# Based on work from:
+#    Bill Nottingham <[EMAIL PROTECTED]>
+#    Peter Jones <[EMAIL PROTECTED]>
+#    David Zeuthen <[EMAIL PROTECTED]>
+#    Richard Hughes <[EMAIL PROTECTED]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+# The rule here? Simplicity.
+
+help_options() {
+	echo "${0##*/} [options]"
+	echo
+	echo "Options can change how the supend or hibernate is done."
+	echo
+	echo "Possible actions are:"
+	echo
+	echo "  --quirk-dpms-on"
+	echo "  --quirk-dpms-suspend"
+	echo "  --quirk-radeon-off"
+	echo "  --quirk-reset-brightness"
+	echo "  --quirk-s3-bios"
+	echo "  --quirk-s3-mode"
+	echo "  --quirk-vbe-post"
+	echo "  --quirk-vbemode-restore"
+	echo "  --quirk-vbestate-restore"
+	echo "  --quirk-vga-mode3"
+	echo
+}
+
+if [ -n "$EUID" -a "$EUID" != "0" ]; then
+	echo This utility may only be run by the root user. 1>&2
+	exit 1
+fi
+
+# Get the command line options
+while [ $# -gt 0 ]
+do
+	case "$1" in
+		--quirk-dpms-on)
+			export DISPLAY_QUIRK_DPMS_ON="true" ;;
+		--quirk-dpms-suspend)
+			export DISPLAY_QUIRK_DPMS_SUSPEND="true" ;;
+		--quirk-radeon-off)
+			export DISPLAY_QUIRK_RADEON_OFF="true" ;;
+		--quirk-reset-brightness)
+			export DISPLAY_QUIRK_RESET_BRIGHTNESS="true" ;;
+		--quirk-s3-bios)
+			export DISPLAY_QUIRK_S3_BIOS="true" ;;
+		--quirk-s3-mode)
+			export DISPLAY_QUIRK_S3_MODE="true" ;;
+		--quirk-vbe-post)
+			export DISPLAY_QUIRK_VBE_POST="true" ;;
+		--quirk-vbemode-restore)
+			export DISPLAY_QUIRK_VBEMODE_RESTORE="true" ;;
+		--quirk-vbestate-restore)
+			export DISPLAY_QUIRK_VBESTATE_RESTORE="true" ;;
+		--quirk-vga-mode3)
+			export DISPLAY_QUIRK_VGA_MODE_3="true" ;;
+		--help)
+			help_options
+			exit 0 ;;
+		*)
+			break ;; # terminate while loop
+	esac
+	shift
+done
+
+export PM_FUNCTIONS="/usr/lib/pm-utils/functions"
+. "${PM_FUNCTIONS}"
+
+[ -f /sys/power/state ] || exit 1
+
+
+ACTION=${0##*pm-}
+
+case "$ACTION" in
+	suspend)
+		if ! pm-is-supported --"$ACTION" ; then
+			echo "Error: kernel cannot suspend to ram." 1>&2
+			exit 1
+		fi
+		REVERSE=resume
+		;;
+	hibernate)
+		if ! pm-is-supported --"$ACTION" ; then
+			echo "Error: kernel cannot suspend to disk." 1>&2
+			exit 1
+		fi
+		REVERSE=thaw
+		;;
+	suspend-hybrid)
+		if ! pm-is-supported --"$ACTION" ; then
+			echo "Error: hybrid suspend is not supported." 1>&2
+			exit
+		fi
+		REVERSE=resume
+		;;
+	*)
+		exit 1
+		;;
+esac
+
+export PM_CMDLINE="$@"
+
+pm_main "$(echo $ACTION | tr - _)" "$REVERSE"
+
+exit $?
-- 
1.5.3.8

From f1c9c11681680e059abc0bb56f0b20a726c29f91 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 10:10:54 -0600
Subject: [PATCH] Renamed pm-powersave in preperation for making it location-independent.

---
 src/pm-powersave    |   37 -------------------------------------
 src/pm-powersave.in |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 37 deletions(-)
 delete mode 100755 src/pm-powersave
 create mode 100755 src/pm-powersave.in

diff --git a/src/pm-powersave b/src/pm-powersave
deleted file mode 100755
index 5611586..0000000
--- a/src/pm-powersave
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-# vim:noexpandtab
-# Simple powersave script
-#
-# Copyright 2006 Red Hat, Inc.
-#
-# Based on work from:
-#    Bill Nottingham <[EMAIL PROTECTED]>
-#    Peter Jones <[EMAIL PROTECTED]>
-#    David Zeuthen <[EMAIL PROTECTED]>
-#    Richard Hughes <[EMAIL PROTECTED]>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of version 2 of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-POWERSAVE_LOGFILE="/dev/null"
-PM_FUNCTIONS="/usr/lib/pm-utils/functions"
-. "${PM_FUNCTIONS}"
-
-if [ "x$1" = "xtrue" -o "x$1" = "xfalse" ] ; then
-    init_logfile "${POWERSAVE_LOGFILE}"
-    run_hooks power "$1"
-else
-    echo "Argument needs to be true or false" >&2
-    exit 1
-fi
diff --git a/src/pm-powersave.in b/src/pm-powersave.in
new file mode 100755
index 0000000..5611586
--- /dev/null
+++ b/src/pm-powersave.in
@@ -0,0 +1,37 @@
+#!/bin/sh
+# vim:noexpandtab
+# Simple powersave script
+#
+# Copyright 2006 Red Hat, Inc.
+#
+# Based on work from:
+#    Bill Nottingham <[EMAIL PROTECTED]>
+#    Peter Jones <[EMAIL PROTECTED]>
+#    David Zeuthen <[EMAIL PROTECTED]>
+#    Richard Hughes <[EMAIL PROTECTED]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+POWERSAVE_LOGFILE="/dev/null"
+PM_FUNCTIONS="/usr/lib/pm-utils/functions"
+. "${PM_FUNCTIONS}"
+
+if [ "x$1" = "xtrue" -o "x$1" = "xfalse" ] ; then
+    init_logfile "${POWERSAVE_LOGFILE}"
+    run_hooks power "$1"
+else
+    echo "Argument needs to be true or false" >&2
+    exit 1
+fi
-- 
1.5.3.8

From 8ae41d104086544631aaf76fd213c5ae8a32de64 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 12:45:03 -0600
Subject: [PATCH] Use autotools to make pm-action and pm-powersave location independent.

---
 src/pm-action.in    |    2 +-
 src/pm-powersave.in |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pm-action.in b/src/pm-action.in
index 68dbb93..b9b32dd 100755
--- a/src/pm-action.in
+++ b/src/pm-action.in
@@ -84,7 +84,7 @@ do
 	shift
 done
 
-export PM_FUNCTIONS="/usr/lib/pm-utils/functions"
+export PM_FUNCTIONS="@PM-UTILS-LIBDIR@/functions"
 . "${PM_FUNCTIONS}"
 
 [ -f /sys/power/state ] || exit 1
diff --git a/src/pm-powersave.in b/src/pm-powersave.in
index 5611586..51de744 100755
--- a/src/pm-powersave.in
+++ b/src/pm-powersave.in
@@ -25,7 +25,7 @@
 #
 
 POWERSAVE_LOGFILE="/dev/null"
-PM_FUNCTIONS="/usr/lib/pm-utils/functions"
+PM_FUNCTIONS="@PM-UTILS-LIBDIR@/functions"
 . "${PM_FUNCTIONS}"
 
 if [ "x$1" = "xtrue" -o "x$1" = "xfalse" ] ; then
-- 
1.5.3.8

From e21eff8128eb04e61132c33cef2a36e6fef72765 Mon Sep 17 00:00:00 2001
From: Victor Lowther <[EMAIL PROTECTED]>
Date: Sat, 2 Feb 2008 12:50:44 -0600
Subject: [PATCH] Add cleanfiles in Makefile.am, and actually export PM_FUNCTIONS in pm-powersave

---
 src/Makefile.am     |    2 ++
 src/pm-powersave.in |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 8dce4db..0497c86 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,6 +30,8 @@ acpowerdir = $(bindir)
 acpower_SCRIPTS =		\
 	on_ac_power
 
+CLEANFILES = $(pm_utils_bin_SCRIPTS) $(extra_SCRIPTS)
+
 do_subst = sed -e 's,[EMAIL PROTECTED]@],$(pm_utils_libdir),g' \
 	   -e 's,[EMAIL PROTECTED]@],$(pm_sysconfdir),g'
 
diff --git a/src/pm-powersave.in b/src/pm-powersave.in
index 51de744..f6cea14 100755
--- a/src/pm-powersave.in
+++ b/src/pm-powersave.in
@@ -25,7 +25,7 @@
 #
 
 POWERSAVE_LOGFILE="/dev/null"
-PM_FUNCTIONS="@PM-UTILS-LIBDIR@/functions"
+export PM_FUNCTIONS="@PM-UTILS-LIBDIR@/functions"
 . "${PM_FUNCTIONS}"
 
 if [ "x$1" = "xtrue" -o "x$1" = "xfalse" ] ; then
-- 
1.5.3.8

_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils

Reply via email to