#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  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 OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options $1

mkdir -p $INSTALL/etc/pm/config.d
  cp $PKG_DIR/config.d/* $INSTALL/etc/pm/config.d || true
mkdir -p $INSTALL/etc/pm/power.d
  cp $PKG_DIR/power.d/* $INSTALL/etc/pm/power.d || true
mkdir -p $INSTALL/etc/pm/sleep.d
  cp $PKG_DIR/sleep.d/* $INSTALL/etc/pm/sleep.d || true

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/49bluetooth $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/99video $INSTALL/usr/lib/pm-utils/sleep.d
  chmod +x $INSTALL/usr/lib/pm-utils/sleep.d/*

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
