#!/bin/sh

. config/options

$SCRIPTS/install grep
$SCRIPTS/install dmidecode
$SCRIPTS/install kbd

PKG_DIR=`find $PACKAGES -type d -name $1`

mkdir -p $INSTALL/etc/pm/config.d
mkdir -p $INSTALL/etc/pm/power.d
mkdir -p $INSTALL/etc/pm/sleep.d

mkdir -p $INSTALL/usr/bin
  for file in import-fdi-quirkdb on_ac_power pm-is-supported; do
    cp -P $PKG_BUILD/src/$file $INSTALL/usr/bin
  done

mkdir -p $INSTALL/usr/lib/pm-utils/bin
  for file in pm-action pm-pmu pm-reset-swap service; do
    cp -P $PKG_BUILD/src/$file $INSTALL/usr/lib/pm-utils/bin
  done

mkdir -p $INSTALL/usr/lib/pm-utils/
  for file in defaults functions pm-functions; do
    cp -P $PKG_BUILD/pm/$file $INSTALL/usr/lib/pm-utils
  done

mkdir -p $INSTALL/usr/lib/pm-utils/video-quirks/
  cp $PKG_DIR/quirks/*.quirkdb $INSTALL/usr/lib/pm-utils/video-quirks/

mkdir -p $INSTALL/usr/lib/pm-utils/module.d
# tuxonice
  for file in kernel uswsusp; do
    cp -P $PKG_BUILD/pm/module.d/$file $INSTALL/usr/lib/pm-utils/module.d
  done

mkdir -p $INSTALL/usr/lib/pm-utils/power.d
# disabled, because not needed
#  for file in sched-powersave; do
#    cp -P $PKG_BUILD/pm/power.d/$file $INSTALL/usr/lib/pm-utils/power.d
#    chmod +x $INSTALL/usr/lib/pm-utils/power.d/$file
#  done

mkdir -p $INSTALL/usr/lib/pm-utils/sleep.d
# 01grub 49bluetooth 55NetworkManager 90clock 95led
  for file in 00logging 00powersave 75modules 94cpufreq 98video-quirk-db-handler 99video; do
    cp -P $PKG_BUILD/pm/sleep.d/$file $INSTALL/usr/lib/pm-utils/sleep.d
    chmod +x $INSTALL/usr/lib/pm-utils/sleep.d/$file
  done

mkdir -p $INSTALL/usr/sbin
  cp -P $PKG_BUILD/src/pm-powersave $INSTALL/usr/sbin
  for file in pm-hibernate pm-suspend pm-suspend-hybrid; do
    ln -sf /usr/lib/pm-utils/bin/pm-action $INSTALL/usr/sbin/$file
  done
