#!/bin/bash
source /etc/conf.d/vdr.admin.cfg

NVRAMCFG="/_config/bin/nvram-wakeup.conf"
NVRAMCFGN="/_config/install/nvram-wakeup.conf"

if [ "$1" != "" ] ; then
   NVRAM=$1
   $SETVAL WAKEUP_METHOD $1
else
   NVRAM=`$GETVAL WAKEUP_METHOD`
fi

if [ "$NVRAM" = "Aus" ] || [ "$NVRAM" = "ACTIVY" ] || [ "$NVRAM" = "ACPI" ] ; then
   if [ -f /usr/bin/nvram-wakeup ] ; then
      mv -f /usr/bin/nvram-wakeup /usr/bin/nvram-wakeup.org
   fi
else
   rm -f $NVRAMCFG

   if [ "$NVRAM" = "MP_QDI" ]  ; then
      NV="$NVRAMCFGN.qdi"
   elif [ "$NVRAM" = "MP_AVT121" ]  ; then
      NV="$NVRAMCFGN.av121"
   elif [ "$NVRAM" = "MP_AVT122" ]  ; then
      NV="$NVRAMCFGN.av122"
   else
      NV=""
   fi
   if [ "$NV" != "" ] ; then
      mv -f $NV $NVRAMCFG
   fi

   if [ -f /usr/bin/nvram-wakeup.org ] ; then
      mv -f /usr/bin/nvram-wakeup.org /usr/bin/nvram-wakeup
   fi

fi
echo 'Done!'
exit 0

