#!/bin/sh
#
#
# chkconfig: 345 04 05
# description: This startup script disables NetworkManager on already up ifaces
#              and set up them to use dhcpcd -p

WITHOUT_RC_COMPAT=1


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

RETVAL=0

start()
{
	 if ip -o a | grep -q 'eth.*UP' ; then 
		 iface=$(ip -o a | grep 'eth.*UP' | cut -f 2 -d' ' | tr -d ':')
		 mkdir -p /etc/net/ifaces/$iface
		 echo 'NM_CONTROLLED=no' >> /etc/net/ifaces/$iface/options
		 echo 'BOOTPROTO=dhcp' >> /etc/net/ifaces/$iface/options
		 echo 'DHCP_ARGS=-p' >> /etc/net/ifaces/$iface/options
		 dhcpcd -p $iface
	 fi
	true
}

stop()
{
	true
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	*)
		msg_usage "${0##*/} {start|stop}"
		RETVAL=1
esac

exit $RETVAL
