summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS20
-rw-r--r--README.debugging7
-rw-r--r--README.distributions2
-rw-r--r--TODO8
-rw-r--r--configure.ac2
-rw-r--r--pm/pm-functions.in4
-rw-r--r--pm/power.d/Makefile.am3
-rw-r--r--pm/power.d/disable_wol6
-rwxr-xr-xpm/power.d/hal-cd-polling53
-rw-r--r--pm/power.d/harddrive8
-rw-r--r--pm/power.d/intel-audio-powersave5
-rw-r--r--pm/power.d/journal-commit4
-rw-r--r--pm/power.d/laptop-mode3
-rw-r--r--pm/power.d/readahead3
-rw-r--r--pm/power.d/sata_alpm6
-rw-r--r--pm/power.d/wireless21
-rwxr-xr-xpm/sleep.d/55NetworkManager10
-rwxr-xr-xpm/sleep.d/75modules4
-rwxr-xr-xpm/sleep.d/90clock8
-rwxr-xr-xpm/sleep.d/98video-quirk-db-handler25
-rw-r--r--src/Makefile.am4
-rw-r--r--src/import-fdi-quirkdb.in150
22 files changed, 163 insertions, 193 deletions
diff --git a/NEWS b/NEWS
index 32cbb30..a8ca542 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,23 @@
+Major changes since the 1.3 series:
+
+* The pm-utils git tree includes infrastructure to build .deb packages,
+ .rpm packages. and Arch Linux .tar packages. These are not intended
+ to replace distro packaging, and are not included in the release tarballs.
+
+* We include some basic power management hooks. The individual hooks can
+ conflict with the ones provided by the laptop-mode-tools scripts, so you
+ should either just remove laptop-mode-tools entirely or pick and choose
+ between which package should handle what powersaving functionality.
+
+Major changes since the 1.2 series:
+
+* We no longer rely on HAL at all for video quirks.
+
+* The pm-utils project has taken over maintenance of the video quirk database.
+ Most systems coming out no longer rely on quirks, due to KMS enabled drivers
+ for most common chipsets along with the two major binary video drivers
+ handling any needed suspend/resume handling themselves.
+
Major changes since the 1.1 series:
* Our pkg-config support now includes variables that directly map to where
diff --git a/README.debugging b/README.debugging
index 96d2638..8230f05 100644
--- a/README.debugging
+++ b/README.debugging
@@ -40,7 +40,7 @@ End-user customization and debugging:
* To override the usual quirk filtering (for kernel modesetting, binary drivers,
and exotic hardware), pass --quirk-test along with any other quirks you want
- to try. This make make your system crash in new and exciting ways by
+ to try. This may make your system crash in new and exciting ways by
conflicting with the kernel when suspending or resuming, but is very useful
for debugging. You have been warned.
@@ -57,4 +57,7 @@ Significant conceptual changes from pm-utils 0.99.x and earlier:
* All scripts created and maintained by the pm-utils are POSIX/SuS compliant.
Any modification or new script should be POSIX compliant and work as intended
- using dash and posh before you submit a patch upstream.
+ using dash and posh before you submit a patch upstream. The sole exception is
+ the video quirk database handler, which would be a couple of orders of
+ magnitude slower when written in POSIX sh, due to how heavily it relies on
+ bash native regular expression support.
diff --git a/README.distributions b/README.distributions
index 58cfbdb..4522969 100644
--- a/README.distributions
+++ b/README.distributions
@@ -3,7 +3,7 @@ Note for distro maintainers:
When writing sleep hooks, please consider adding any needed hooks to the package
that requires the hooks, rather than pm-utils.
-An example would be if you distro wants anacrom to run on resume -- the optimal
+An example would be if you distro wants anacron to run on resume -- the optimal
fix would be to have the anacron package install a hook in
/usr/lib/pm-utils/sleep.d that wakes anacron up on resume.
diff --git a/TODO b/TODO
index bb3ab1d..a5eed93 100644
--- a/TODO
+++ b/TODO
@@ -8,14 +8,6 @@
it has to do that on its own. A simple parameter-parsing engine
might come in handy.
-* Currently, we really only handle suspend/resume. The
- powermanagement system should use some maintenance. Should we also
- handle other powermanagement-related tasks?
-
-* Beef up the abstraction layer between the hooks and the pm-utils
- core infrastructure. We should work on making that API stable
- enough that...
-
* pm-utils to become the default low-level userspace power management handling
infrastructure for the majority of Linux (and mabye other
unixalikes) distributions. The core pm-utils infrastructure is
diff --git a/configure.ac b/configure.ac
index a51cb91..336c3b5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ(2.52)
-AC_INIT(pm-utils, 1.3.0)
+AC_INIT(pm-utils, 1.4.0-rc2)
AC_CONFIG_SRCDIR(src)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_CONFIG_HEADER(config.h)
diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index 9a25b10..c82be30 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -195,8 +195,10 @@ hook_ok()
_run_hook() {
# $1 = hook to run
# rest of args passed to hook unchanged.
- log -n "$*:"
+ log "Running hook $*:"
hook_ok "$1" && "$@"
+ log ""
+ log -n "$*: "
hook_exit_status $? && LAST_HOOK="${1##*/}" || inhibit
}
diff --git a/pm/power.d/Makefile.am b/pm/power.d/Makefile.am
index 38e40a1..88cff47 100644
--- a/pm/power.d/Makefile.am
+++ b/pm/power.d/Makefile.am
@@ -11,7 +11,8 @@ power_SCRIPTS = \
journal-commit \
disable_wol \
pcie_aspm \
- sata_alpm
+ sata_alpm \
+ hal-cd-polling
EXTRA_DIST=$(power_SCRIPTS)
diff --git a/pm/power.d/disable_wol b/pm/power.d/disable_wol
index 4c720fb..027eec5 100644
--- a/pm/power.d/disable_wol
+++ b/pm/power.d/disable_wol
@@ -8,10 +8,12 @@ set_wol_status() {
for d in "/sys/class/net/"*; do
[ -f "$d/wireless" ] && continue
[ -h "$d/device/driver" ] || continue
+ printf "Setting Wake On Lan for %s to %s..." "${d##*/}" "$1"
case $1 in
- disable) ethtool -s "${d##*/}" wol d;;
- enable) ethtool -s "${d##*/}" wol g;;
+ disable) ethtool -s "${d##*/}" wol d>/dev/null 2>&1;;
+ enable) ethtool -s "${d##*/}" wol g>/dev/null 2>&1;;
esac
+ [ "$?" -eq 0 ] && echo Done. || echo Failed.
done
}
diff --git a/pm/power.d/hal-cd-polling b/pm/power.d/hal-cd-polling
new file mode 100755
index 0000000..51d161d
--- /dev/null
+++ b/pm/power.d/hal-cd-polling
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+. "${PM_FUNCTIONS}"
+
+DISABLE_HAL_POLLING="${DISABLE_HAL_POLLING:-true}"
+
+
+help() {
+ cat <<"EOF"
+---
+$0: Keep HAL from polling optical media for disk insertion
+
+Keep HAL from polling optical media while on battery. This saves a few
+tenths of a watt.
+
+This hook has 1 parameter:
+DISABLE_HAL_POLLING = true or false.
+If true, this hook will turn off the poll HAL does every 2 seconds to see
+if media has been inserted into an optical drive.
+
+If false, this hook does nothing.
+
+EOF
+}
+
+stop_polling() {
+ [ "$DISABLE_HAL_POLLING" = "true" ] || exit $NA
+ command_exists hal-disable-polling || exit $NA
+ local disks="$(for c in /dev/cd/*; do readlink -f "$c"; done |sort |uniq)"
+ [ "$disks" ] || exit $NA
+ savestate hal_polling_disks "$disks"
+ for c in $disks; do
+ printf "Disabling HAL polling of %s..." "$c"
+ hal-disable-polling --device "$c" >/dev/null 2>&1 \
+ && echo Done. || echo Failed.
+ done
+}
+
+restart_polling() {
+ state_exists hal_polling_disks || exit $NA
+ for disk in $(restorestate hal_polling_disks); do
+ printf "Reenabling HAL polling of %s..." "$disk"
+ hal-disable-polling --enable-polling --device "$disk" && echo Done || \
+ echo Failed.
+ done
+}
+
+case $1 in
+ true) stop_polling;;
+ false) restart_polling;;
+ help) help;;
+ *) exit $NA;;
+esac
diff --git a/pm/power.d/harddrive b/pm/power.d/harddrive
index a454170..5b257cd 100644
--- a/pm/power.d/harddrive
+++ b/pm/power.d/harddrive
@@ -64,20 +64,24 @@ harddrive_ac () {
for dev in $DRIVE_LIST; do
# disable write caching, do not spin down the drive, disable APM
# and acoustic management, and sync everything to drive.
+ printf "Disabling hard drive power management for %s..." "$dev"
hdparm -W $DRIVE_WRITE_CACHE_AC \
-S $DRIVE_SPINDOWN_VALUE_AC \
-B $DRIVE_POWER_MGMT_AC \
- -M $DRIVE_ACOUSTIC_MGMT_AC $dev
+ -M $DRIVE_ACOUSTIC_MGMT_AC $dev >/dev/null 2>&1 \
+ && echo Done. || echo Failed.
done
}
harddrive_battery() {
for dev in $DRIVE_LIST; do
# disable write caching, enable acoustic management
+ printf "Enabling power management for %s..." "$dev"
hdparm -W $DRIVE_WRITE_CACHE_BAT \
-S $DRIVE_SPINDOWN_VALUE_BAT \
-B $DRIVE_POWER_MGMT_BAT \
- -M $DRIVE_ACOUSTIC_MGMT_BAT -F $dev
+ -M $DRIVE_ACOUSTIC_MGMT_BAT -F $dev >/dev/null 2>&1 \
+ && echo Done. || echo Failed.
done
}
diff --git a/pm/power.d/intel-audio-powersave b/pm/power.d/intel-audio-powersave
index 0e7eab7..36675a8 100644
--- a/pm/power.d/intel-audio-powersave
+++ b/pm/power.d/intel-audio-powersave
@@ -19,8 +19,11 @@ EOF
}
audio_powersave() {
+ [ "$INTEL_AUDIO_POWERSAVE" = "true" ] || exit $NA
for dev in /sys/module/snd_*/parameters/power_save; do
- [ -w $dev ] && [ "$INTEL_AUDIO_POWERSAVE" = "true" ] && echo $1 > $dev
+ [ -w "$dev/parameters/power_save" ] || continue
+ printf "Setting power savings for $s to %d..." "$dev##*/" "$1"
+ echo $1 > "$dev/parameters/power_save" && echo Done. || echo Failed.
done
}
diff --git a/pm/power.d/journal-commit b/pm/power.d/journal-commit
index ee8920c..5c0fc16 100644
--- a/pm/power.d/journal-commit
+++ b/pm/power.d/journal-commit
@@ -43,7 +43,9 @@ handle_filesystems()
while read DEV MOUNT FSTYPE REST;
do
command_exists "handle_${FSTYPE}" || continue
- "handle_${FSTYPE}" $MOUNT $1
+ printf "Setting journal commit time for %s to %d..." \
+ "$MOUNT" "$1"
+ "handle_${FSTYPE}" $MOUNT $1 && echo Done. || echo Failed.
done < /proc/mounts
}
diff --git a/pm/power.d/laptop-mode b/pm/power.d/laptop-mode
index 5f873db..601b260 100644
--- a/pm/power.d/laptop-mode
+++ b/pm/power.d/laptop-mode
@@ -43,7 +43,6 @@ wakeups of the pdflush daemons.
Defaults to 60000 (10 minutes), which menas that the kernel will flush dirty
memory every 10 minutes if dirty memory never hits 40% of system memory.
-
EOF
}
@@ -69,6 +68,7 @@ laptop_mode_ac() {
else
write_values 0 10 5 500
fi
+ echo "Laptop mode disabled."
}
laptop_mode_battery() {
@@ -78,6 +78,7 @@ laptop_mode_battery() {
read_values | savestate laptop_mode_default
write_values "$LAPTOP_MODE" "$LAPTOP_DIRTY_RATIO" \
"$LAPTOP_DIRTY_BG_RATIO" "$LAPTOP_DIRTY_WRITEBACK"
+ echo "Laptop mode enabled."
}
case $1 in
diff --git a/pm/power.d/readahead b/pm/power.d/readahead
index 2009c84..7b337bc 100644
--- a/pm/power.d/readahead
+++ b/pm/power.d/readahead
@@ -32,7 +32,8 @@ readahead() {
# More sophistication in figuring out what exactly is a local block device
# would be welcome.
for dev in $(awk '/^\/dev\// {print $1}'</etc/mtab); do
- /sbin/blockdev --setfra $1 "$dev"
+ printf "Setting readahead for %s to %d..." "$dev" "$1"
+ /sbin/blockdev --setfra $1 "$dev" && echo Done. || echo Failed.
done
}
diff --git a/pm/power.d/sata_alpm b/pm/power.d/sata_alpm
index 6391e09..dbe4117 100644
--- a/pm/power.d/sata_alpm
+++ b/pm/power.d/sata_alpm
@@ -27,8 +27,10 @@ set_sata_alpm() {
[ "$kv" ] || exit $NA #for paranoia's sake
[ "${kv%-*}" \< "2.6.33" ] && exit $NA # avoid fs corruption
for f in /sys/class/scsi_host/host*/link_power_management_policy; do
- [ -w "$f" ] || continue
- echo "$1" > "$f"
+ [ -w "$f/link_power_management_policy" ] || continue
+ printf "Setting SATA APLM on %s to %s..." "${f##*/}" "$1"
+ echo "$1" > "$f/link_power_management_policy" && echo Done. || \
+ echo Failed.
done
}
diff --git a/pm/power.d/wireless b/pm/power.d/wireless
index 0487dc1..b4be69c 100644
--- a/pm/power.d/wireless
+++ b/pm/power.d/wireless
@@ -1,5 +1,7 @@
#!/bin/sh
+. "${PM_FUNCTIONS}"
+
# See if we have the usual wireless tools.
# Do not just fail because not all cards require these.
which iwpriv >/dev/null 2>&1 && have_iwpriv="true"
@@ -18,7 +20,7 @@ get_wireless_params() {
# Skip if not a wireless card.
[ -d "/sys/class/net/$1/wireless" ] || return 1
# Also don't do anything if the device is disabled
- [ "$(cat /sys/class/net/$1/device/enabled)" = "1" ] || return 1
+ [ "$(cat /sys/class/net/$1/device/enable)" = "1" ] || return 1
driver="$(readlink "/sys/class/net/$1/device/driver")"
driver=${driver##*/}
case $driver in
@@ -52,10 +54,19 @@ get_wireless_params() {
wireless_powersave() {
for dev in /sys/class/net/*; do
- get_wireless_params "${dev##*/}" "$1"
- [ "$have_iwconfig" = true -a "$iwconfig" ] && iwconfig $iwconfig
- [ "$have_iwpriv" = true -a "$iwpriv" ] && iwpriv $iwpriv
- [ "$iwlevel" ] && echo "$iwlevel" > "$dev/device/power_level"
+ get_wireless_params "${dev##*/}" "$1" || continue
+ ret=0
+ printf "Turning powersave for %s %s..." "${dev##*/}" "$1"
+ if [ "$have_iwconfig" = true -a "$iwconfig" ]; then
+ iwconfig "${dev##*/}" $iwconfig || ret=1
+ fi
+ if [ "$have_iwpriv" = true -a "$iwpriv" ]; then
+ iwpriv "${dev##*/}" $iwpriv || ret=1
+ fi
+ if [ "$iwlevel" ]; then
+ echo "$iwlevel" > "$dev/device/power_level" || ret=1
+ fi
+ [ "$ret" -eq 0 ] && echo Done. || echo Failed.
done
}
diff --git a/pm/sleep.d/55NetworkManager b/pm/sleep.d/55NetworkManager
index bc0cf5a..f3c6df5 100755
--- a/pm/sleep.d/55NetworkManager
+++ b/pm/sleep.d/55NetworkManager
@@ -11,19 +11,23 @@
suspend_nm()
{
# Tell NetworkManager to shut down networking
+ printf "Having NetworkManager put all interaces to sleep..."
dbus_send --system \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.sleep
+ org.freedesktop.NetworkManager.sleep && \
+ echo Done. || echo Failed.
}
resume_nm()
{
# Wake up NetworkManager and make it do a new connection
- dbus_send --system \
+ printf "Having NetworkManager wake interfaces back up..."
+ dbus_send --system \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.wake
+ org.freedesktop.NetworkManager.wake && \
+ echo Done. || echo Failed.
}
case "$1" in
diff --git a/pm/sleep.d/75modules b/pm/sleep.d/75modules
index 3f292e4..261e70d 100755
--- a/pm/sleep.d/75modules
+++ b/pm/sleep.d/75modules
@@ -7,7 +7,8 @@ suspend_modules()
{
[ -z "$SUSPEND_MODULES" ] && return $NA
for x in $SUSPEND_MODULES ; do
- modunload $x
+ printf "Unloading kernel module %s..." "$x"
+ modunload $x && echo Done. || echo Failed.
done
return 0
}
@@ -15,6 +16,7 @@ suspend_modules()
resume_modules()
{
modreload
+ echo "Reloaded unloaded modules."
}
case "$1" in
diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock
index b8ade29..d81e2a6 100755
--- a/pm/sleep.d/90clock
+++ b/pm/sleep.d/90clock
@@ -6,12 +6,16 @@
suspend_clock()
{
- /sbin/hwclock --systohc >/dev/null 2>&1 0<&1
+ printf "Saving system time to hardware clock..."
+ /sbin/hwclock --systohc >/dev/null 2>&1 0<&1 && echo Done. || \
+ echo Failed.
}
resume_clock()
{
- /sbin/hwclock --hctosys >/dev/null 2>&1 0<&1
+ printf "Loading system time from hardware clock..."
+ /sbin/hwclock --hctosys >/dev/null 2>&1 0<&1 && echo Done. || \
+ echo Failed.
}
is_set "$NEED_CLOCK_SYNC" || exit $NA
diff --git a/pm/sleep.d/98video-quirk-db-handler b/pm/sleep.d/98video-quirk-db-handler
index 942a6a9..e9ea3ca 100755
--- a/pm/sleep.d/98video-quirk-db-handler
+++ b/pm/sleep.d/98video-quirk-db-handler
@@ -354,38 +354,45 @@ case $1 in
# Use them without the usual filtering. This may cause the system
# to blow up, but they explicitly asked for it.
remove_parameters --quirk-test
+ echo "Quirk testing mode enabled."
elif using_kms; then
# Using kernel modesetting? No quirks, and do not change vts.
remove_parameters $possible_video_quirks
add_parameters --quirk-no-chvt
+ echo "Kernel modesetting video driver detected, not using quirks."
elif using_nvidia; then
# Ditto for nVidia binary drivers
remove_parameters $possible_video_quirks
+ echo "nVidia binary video drive detected, not using quirks."
elif using_fglrx; then
# fglrx may or may not have to change vts, reports one
# way or the other welcome.
remove_parameters $possible_video_quirks
add_parameters --quirk-none
+ echo "ATI Catalyst driver detected, not using quirks."
elif have_nvidia_g80; then
# nVidia G80 GPUs require special handling when not using nvidia
# binary drivers. I do not know if noveau requires help or not.
remove_parameters $possible_video_quirks
add_parameters --quirk-vbe-post
+ echo "nVidia g80 series card detected."
else
# Go ahead and get our quirks.
if has_video_parameters; then
# Parameters from the command line take precedence
# over the database, so do not query it.
- :
+ echo "Using quirks passed as parameters."
elif [[ $PM_QUIRKS ]]; then
# If we have $PM_QUIRKS. use it instead of the quirk database
add_parameters $PM_QUIRKS
+ echo "Using PM_QUIRKS environment variable for quirks."
# If we were not passed any quirks on the command line,
# get them from the database.
elif QUIRKS=$(find_native "$PM_LKW_QUIRKS"); then
# Known working quirks from our last run are still valid.
# Use them.
add_parameters $QUIRKS
+ echo "Using last known working set of quirks."
else
# Our known working quirks from the last run are either
# nonexistent or invalid. Either way, start over.
@@ -395,11 +402,14 @@ case $1 in
QUIRKS=$(find_native "$f") && break
done
# some default quirks if we did not get any.
- [[ -z $QUIRKS ]] && QUIRKS="--quirk-vbe-post
- --quirk-dpms-on --quirk-dpms-suspend
- --quirk-vbestate-restore
- --quirk-vbemode-restore
- --quirk-vga-mode-3"
+ if [[ -z $QUIRKS ]]; then
+ QUIRKS="--quirk-vbe-post --quirk-dpms-on
+ --quirk-dpms-suspend --quirk-vbestate-restore
+ --quirk-vbemode-restore --quirk-vga-mode-3"
+ echo "No quirk database entry for this system, using default."
+ else
+ echo "Using quirks for this system from quirk database."
+ fi
add_parameters $QUIRKS
savestate video_quirks "$QUIRKS"
fi
@@ -418,6 +428,7 @@ case $1 in
--quirk-radeon-off \
--quirk-no-fb \
--quirk-save-pci
+ echo "Cleaning up quirks not needed by Intel video cards."
fi
fi
;;
@@ -425,6 +436,7 @@ case $1 in
if state_exists video_quirks; then
QUIRKS=$(restorestate video_quirks);
write_last_known_working
+ echo "Saving last known working quirks: $QUIRKS"
elif has_parameter --store-quirks-as-lkw; then
for x in $(get_parameters); do
for y in $possible_video_quirks; do
@@ -432,6 +444,7 @@ case $1 in
done
done
write_last_known_working
+ echo "Saving last known working quirks: $QUIRKS"
fi
;;
esac
diff --git a/src/Makefile.am b/src/Makefile.am
index dbb0e8f..748a956 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,11 +14,11 @@ pm_bin_SCRIPTS = pm-action service
bin_SCRIPTS = pm-is-supported
-dist_bin_SCRIPTS = on_ac_power import-fdi-quirkdb
+dist_bin_SCRIPTS = on_ac_power
sbin_SCRIPTS = pm-powersave
-script_in_files = pm-action.in pm-is-supported.in pm-powersave.in import-fdi-quirkdb.in service
+script_in_files = pm-action.in pm-is-supported.in pm-powersave.in service
CLEANFILES = $(script_in_files:.in=)
diff --git a/src/import-fdi-quirkdb.in b/src/import-fdi-quirkdb.in
deleted file mode 100644
index ff11ffe..0000000
--- a/src/import-fdi-quirkdb.in
+++ /dev/null
@@ -1,150 +0,0 @@
-#!/bin/bash
-# This command imports the native HAL video quirks into the pm-utils native
-# format. It knows just enough about the video quirk .fdi files to translate
-# them into a format that bash can more easily parse.
-
-# While we are at it, replace the .fdi ad-hoc pattern matching language with
-# extended regular expressions where we can.
-
-# If anyone wants fo rewrite this in a language that actually understands
-# XML, feel free.
-
-# If run with no arguments, it will translate the already installed .fdi
-# quirks into the native ones at their default location.
-
-# If run with one argument, it will translate the .fdi quirks located at
-# $1 into the native ones at their default location.
-
-# if run with two arguments, it will translate the .fdi quirks located at $1
-# into the native ones at $2.
-
-. "@PM-UTILS-LIBDIR@/pm-functions"
-shopt -s extglob
-
-begin_match='<match key *= *"([a-z._]+)" ([a-z_]+) *= *"([^"]+)">'
-end_match='</match>'
-merge='<merge key *= *"([^"]+)" type *= *"bool">true</merge>'
-remove='<remove key *= *"([^"]+)"></remove>'
-begin_comment='<!--'
-end_comment='-->'
-in_comment=0
-in_match=0
-
-# test to see if the parameter passed is a decimal or hexidecimal number
-# Note the complete lack of floating point support.
-isnum() {
- [[ $1 =~ ^[0-9]+\$ || $1 =~ ^0[xX][0-9a-fA-F]+\$ ]]
-}
-
-space_echo() {
- for ((i=$1; i>0; i--)); do
- printf ' '
- done
- shift
- echo "$1"
-}
-
-# Helper function for when translating from .fdi to native format,
-# we need to massage things a little.
-escape_match() {
- local fun lit
- fun="regex"
- # first, escape special ere characters
- lit="$2"
- lit="${lit//\\/\\\\}"
- lit="${lit//./\\.}"
- lit="${lit//^/\\^}"
- lit="${lit//[/\\[}"
- lit="${lit//]/\\]}"
- lit="${lit//\(/\\(}"
- lit="${lit//)/\\)}"
- lit="${lit//\*/\\\*}"
- lit="${lit//\+/\\\+}"
- lit="${lit//\?/\\\?}"
- lit="${lit//\{/\\\{}"
- lit="${lit//\}/\\\}}"
- lit="${lit//\|/\\\|}"
- lit="${lit//\$/\\\$}"
- # second, handle the various comparison cases, munging them into
- # extended regular expressions that bash understands.
- case $1 in
- string) lit="^${lit}\$" ;;
- int|uint64) fun=numeric_compare_eq ;;
- string_outof) lit="${lit%;}"; lit="^(${lit//;/|})\$" ;;
- int_outof) fun=numeric_compare_eq_list ;;
- contains) ;;
- contains_outof) lit="${lit%;}"; lit="${lit//;/|}" ;;
- prefix) lit="^${lit}" ;;
- prefix_outof) lit="${lit%;}"; lit="^(${lit//;/|})" ;;
- suffix) lit="${lit}\$" ;;
- contains_ncase) fun=regex_ncase ;;
- contains_not) fun=regex_inverse ;;
- prefix_ncase) fun=regex_ncase; lit="^${lit}" ;;
- suffix_ncase) fun=regex_ncase; lit="${lit}\$" ;;
- compare_lt|compare_le|compare_gt|compare_ge|compare_ne)
- # I know, this may not always be the right thing to do.
- # It is the right thing most of the time, though.
- if isnum "$lit"; then
- fun="numeric_$1"
- else
- fun="$1"
- fi
- ;;
- *) echo "$1 not implemented." >&2 ; exit 1 ;;
- esac
- echo "$fun $lit"
-}
-
-# This is so not the right way to parse XML, but it happens to work with
-# the current hal-info video quirk .fdi files. Maybe someday I will rewrite
-# this in a language that actually understands XML, even though XML is the devil.
-translate_xml() {
- local line key val matcher in_comment in_matcher
- while read line; do
- [[ "$line" ]] || continue
- if [[ $line =~ $begin_comment && $line =~ $end_comment ]]; then
- space_echo $in_match "# $line"
- elif [[ $line =~ $begin_comment ]]; then
- space_echo $in_match "# $line"
- ((in_comment++))
- elif [[ $line =~ $end_comment ]]; then
- space_echo $in_match "# $line"
- ((in_comment--))
- elif ((in_comment > 0)); then
- space_echo $in_match "# $line"
- elif [[ $line =~ $begin_match ]]; then
- ((in_match++))
- key="${BASH_REMATCH[1]}"
- matcher="${BASH_REMATCH[2]}"
- val="${BASH_REMATCH[3]}"
- space_echo $in_match "match $key $(escape_match "$matcher" "$val")"
- elif [[ $line =~ $end_match ]]; then
- space_echo $in_match "endmatch"
- ((in_match--))
- elif [[ $line =~ $merge ]]; then
- key="${BASH_REMATCH[1]##*.}"
- space_echo $((in_match + 1)) "addquirk --quirk-${key//_/-}"
- elif [[ $line =~ $remove ]]; then
- key="${BASH_REMATCH[1]##*.}"
- space_echo $((in_match + 1)) "delquirk --quirk-${key//_/-}"
- fi
- done
-
-}
-
-loc="/usr/share/hal/fdi/information/10freedesktop/20-video-quirk*.fdi"
-[[ $1 && -d $1 ]] && loc="$1/20-video-quirk*.fdi"
-[[ $2 ]] && PM_QUIRKDB="$2"
-
-
-mkdir -p "$PM_QUIRKDB"
-for f in $loc;
-do
- lf="$PM_QUIRKDB/${f##*/}"
- lf="${lf%.*}.quirkdb"
- [[ -f $f ]] || continue
- [[ $f -nt $lf ]] || continue
- translate_xml < "$f" > "$lf"
- rm "$PM_LKW_QUIRKS" >/dev/null 2>&1
-done
-