#!/bin/sh
cfg="/boot/config/simpleFeatures.cfg"
ini="/var/local/emhttp/simpleFeatures.ini"
tmp="/tmp/go.tmp"
go="/boot/config/go"

# Sleep settings
section="sleep"
echo "[$section]" >> $ini
before=$(du -b $ini | cut -f1)
if [ -f $cfg ]; then
# Create custom settings
  grep "^$section\." $cfg | sed "s:^$section\.::" >> $ini
fi
after=$(du -b $ini | cut -f1)
if [ $before -eq $after ]; then
# Create default settings
  echo 's3="0"'        >> $ini
  echo 'checkHDD="-a"' >> $ini
  echo 'timeout="30"'  >> $ini
  echo 'eth="eth0"'    >> $ini
  echo 'interval="5"'  >> $ini
  echo 'checkTCP=""'   >> $ini
  echo 'pingIP=""'     >> $ini
  echo 'stopDay=""'    >> $ini
  echo 'stopHour=""'   >> $ini
  echo 'dhcpRenew=""'  >> $ini
  echo 'forceGb=""'    >> $ini
  echo 'setWol=""'     >> $ini
  echo 'preRun=""'     >> $ini
  echo 'postRun=""'    >> $ini
# Remove s3_sleep reference (if existing)
  grep -v 's3_sleep' $go > $tmp
  mv -f $tmp $go
fi