OpenNetAdmin

Search:   

Here is a contributed script that uses the build_dhcpd module to configure a bind service. It will only update the configuration when something changed in the ONA database. You'll need dcm.pl script to make it work.

It works for FreeBSD, but editing a few variables will make it work for any *nix.

#!/bin/sh

BINDIR=`dirname $0`
CONFDIR=${BINDIR}/../etc

DCM_PATH=${BINDIR}/dcm/dcm.pl
DCM_CONF_FILE=${CONFDIR}/dcm.conf

HOSTNAME=`hostname`

# What must be excluded from the diff algo
EXCLUDE="dhcpd.conf file for ${HOSTNAME} built on" 

# Temp result file without ${EXCLUDE}
TEMP=/tmp/temp_dhcpd.conf
# Dest result file without ${EXCLUDE}
DEST_DIFF=/tmp/temp_dest_dhcpd.conf
# Result file with ${EXCLUDE}
SOURCE=/tmp/source_dhcpd.conf

DHCP_CONF=/usr/local/etc/dhcpd.conf
DHCP_INIT=/usr/local/etc/rc.d/isc-dhcpd

DHCP=/usr/local/sbin/dhcpd
DIFF=/tmp/diff_dhcp

${DCM_PATH} -c ${DCM_CONF_FILE} -r build_dhcpd_conf server=${HOSTNAME} header_path=${CONFDIR}/dcm_includes.list \
	| tee ${SOURCE} \
	| egrep -v "${EXCLUDE}" > ${TEMP}

if [ $? != 0 ];then
	echo "Problem getting configuration from DCM"
	rm ${TEMP} ${SOURCE}
	exit 1
fi

egrep -v "${EXCLUDE}" ${DHCP_CONF} > ${DEST_DIFF}

diff ${DEST_DIFF} ${TEMP}  > ${DIFF}

if [ ! -s ${DIFF} ];then
	# No difference: do anything
	#echo "No diff"
	rm ${TEMP} ${SOURCE} ${DEST_DIFF} ${DIFF}
	exit 0
fi

if ! ${DHCP} -cf ${SOURCE} -t > /dev/null 2>&1
then
    ${DHCP} -cf ${TEMP} -t 2>&1
    echo "The resulting config files have a syntax error."
    rm ${TEMP} ${SOURCE} ${DEST_DIFF} ${DIFF}
    exit 2
fi

echo "Updating DHCP configuration"
echo "new configuration:"
cat ${DIFF}
mv ${SOURCE} ${DHCP_CONF}
rm ${DIFF} ${TEMP} ${DEST_DIFF}
${DHCP_INIT} restart > /dev/null 2>&1 
 
contrib/contributeddhcpscript.txt · Last modified: 2011/03/29 10:13 by grrrreg