#!/bin/bash
#
# Scripts that creates the initial config for dhcpd
#

DHCPD_CONF=/replicated/etc/dhcpd.conf

# Check if the we already have config installed
if [ -s "${DHCPD_CONF}" ]; then
    exit
fi


# Copy our initial template.
cp -f ./conf/dhcpd.conf ${DHCPD_CONF}

# Add an omapi key to the initial dhcpd.conf.
/usr/local/sbin/rndc-confgen -a -A hmac-sha512 -k omapikey -c /tmp/omapikey.conf >> /dev/null 2>&1
cat /tmp/omapikey.conf >> ${DHCPD_CONF}
rm -f /tmp/omapikey.conf

cat <<EOF >> ${DHCPD_CONF}

omapi-key omapikey;
omapi-port 7911;

EOF

chown root:root ${DHCPD_CONF}
chmod 664 ${DHCPD_CONF}


