#!/bin/sh

test -d /etc/rc2.d-disabled || mkdir /etc/rc2.d-disabled
for i in \
	minihttpd;
do
	test ! -f /etc/rc2.d-disabled/*$i && mv /etc/rc2.d/*$i /etc/rc2.d-disabled/
done

#sed -e 's,^CMDLINE="/sbin/mini_httpd -u root,& -p 80,' /etc/init.d/minihttpd

if [ -f /etc/lighttpd/lighttpd.conf ];then
	echo "Changing web root to /srv/www"
	sed -i -e 's,/var/www,/srv/www,' /etc/lighttpd/lighttpd.conf
fi

if [ -f /etc/olsrd.conf ];then
	echo "Enabling nameservice with $(hostname) in /etc/olsrd.conf"
	sed -i -e"
/^#LoadPlugin \+\"olsrd_nameservice/,/#}/{
/LoadPlugin/s/#//
/{/s/#//
/\"suffix\"/s/#//
/\"latlon-file\"/s/#//
/\"interval\"/s/#//
/\"timeout\"/s/#//
/}/{
  s/#//
  i\
PlParam \"name\" \"$(hostname)\"
  }
}
" /etc/olsrd.conf
fi

if [ -x /etc/init.d/ntpdate ] && ! grep -q startdelayed /etc/init.d/ntpdate;then
	echo "Adding 60 seconds to NTP startup"
	sed -i -e'
/^[ 	]*start[^a-z]/{
a\
  exec $0 startdelayed&\
  ;;\
startdelayed)\
  sleep 60
}
' /etc/init.d/ntpdate
fi

# We send this long-runner to the background (needs up to 45 seconds)
if ! grep -q \"background\" /etc/hotplug/usb.rc;then
	sed -i -e'
2i\
test "$1" != "background" && {\
	$0 background $*&\
	# Sometimes X11 is up too fast\
	modprobe hid\
	exit 0\
}\
shift
' /etc/hotplug/usb.rc
fi

if ! grep -q cron.hdasleep /etc/cron/crontabs/root;then
  echo "0-59/5 * * * *  /usr/sbin/cron.hdasleep">>/etc/cron/crontabs/root
fi
