#!/bin/sh

. config/options $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
  cp $PKG_BUILD/src/on_ac_power $INSTALL/usr/bin
  cp $PKG_BUILD/src/pm-is-supported $INSTALL/usr/bin

mkdir -p $INSTALL/usr/lib/pm-utils/
  cp $PKG_BUILD/pm/defaults $INSTALL/usr/lib/pm-utils
  cp $PKG_BUILD/pm/functions $INSTALL/usr/lib/pm-utils
  cp $PKG_BUILD/pm/pm-functions $INSTALL/usr/lib/pm-utils

mkdir -p $INSTALL/usr/lib/pm-utils/bin
  cp $PKG_BUILD/src/pm-action $INSTALL/usr/lib/pm-utils/bin
  cp $PKG_BUILD/src/pm-pmu $INSTALL/usr/lib/pm-utils/bin
  cp $PKG_BUILD/src/pm-reset-swap $INSTALL/usr/lib/pm-utils/bin
  cp $PKG_BUILD/src/service $INSTALL/usr/lib/pm-utils/bin

mkdir -p $INSTALL/usr/lib/pm-utils/module.d
  cp $PKG_BUILD/pm/module.d/kernel $INSTALL/usr/lib/pm-utils/module.d
  cp $PKG_BUILD/pm/module.d/uswsusp $INSTALL/usr/lib/pm-utils/module.d
  cp $PKG_BUILD/pm/module.d/tuxonice $INSTALL/usr/lib/pm-utils/module.d

mkdir -p $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/disable_wol $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/harddrive $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/hal-cd-polling $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/journal-commit $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/intel-audio-powersave $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/pcie_aspm $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/laptop-mode $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/sata_alpm $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/readahead $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/sched-powersave $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/wireless $INSTALL/usr/lib/pm-utils/power.d
  cp $PKG_BUILD/pm/power.d/xfs_buffer $INSTALL/usr/lib/pm-utils/power.d
  chmod +x $INSTALL/usr/lib/pm-utils/power.d/*

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

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/sbin
  cp $PKG_BUILD/src/pm-powersave $INSTALL/usr/sbin
    ln -sf /usr/lib/pm-utils/bin/pm-action $INSTALL/usr/sbin/pm-hibernate
    ln -sf /usr/lib/pm-utils/bin/pm-action $INSTALL/usr/sbin/pm-suspend
    ln -sf /usr/lib/pm-utils/bin/pm-action $INSTALL/usr/sbin/pm-suspend-hybrid
