#!/bin/bash

# Remove pre-upgrade hook
rm -f etc/init/upgrade.conf

# disable all services
if [ -f /sbin/chkconfig ] && [ -f /bin/grep ] && [ -f /bin/sed ] ; then 
for i in `LANG=C /sbin/chkconfig --list | grep -v "xinetd based services:" | sed -e "s/\([^ ]*\)[ ]*0.*/\1/" -e "s/[\t]\(.*\):.*/\1/"`; do
	[ -x etc/init.d/$i ] && /sbin/chkconfig --level 3 $i off > /dev/null 2>&1
done
fi

# turn services on
list="network httpd iptables sshd xinetd saslauthd sendmail rsyslog crond"
for i in $list; do
	/sbin/chkconfig --level 3 $i on > /dev/null 2>&1	
done

# Fix /etc/rsyslog.conf
CFG_FILE=etc/rsyslog.conf
if [ -f $CFG_FILE ]; then
	echo -e ',s^\([[:space:]]\)\(/var/log/\)^\\1-\\2^\nwq' | ed -s $CFG_FILE
fi

# Create empty modules.dep on container start
echo "#!/bin/bash
# Fix modules.dep for iptables
#
# chkconfig: 2345 08 92
# description: Simple script that fixed modules.dep for iptables
#

### BEGIN INIT INFO
# Provides: modules_dep
# Required-Start: \$local_fs
# Required-Stop: \$local_fs
# Should-Start: 
# Should-Stop: 
# Default-Start: 
# Default-Stop: 
# Short-Description: Fix modules.dep for iptables
# Description: Simple script that fixed modules.dep for iptables
### END INIT INFO

# source function library
. /etc/init.d/functions

function start() {
        if [ ! -d \"/lib/modules/\`uname -r\`\" ]; then
                mkdir /lib/modules/\`uname -r\`
        fi
        depmod -a >/dev/null 2>&1
}

function stop() {
        if [ -d \"/lib/modules/\`uname -r\`\" ]; then
                rm -rf /lib/modules/\`uname -r\`
        fi
}

case \"\$1\" in
  start)
        start
        RETVAL=0
        ;;
  stop)
        stop
        RETVAL=0
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  try-restart|status)
        RETVAL=0
        ;;
  *)
        echo \$\"Usage: \$0 {start|stop|status|restart|condrestart|reload}\"
        RETVAL=2
esac

exit \$RETVAL" > etc/init.d/modules_dep
chmod 0755 etc/init.d/modules_dep
/sbin/chkconfig --add modules_dep

:
