#!/bin/sh
# Copyright (C) 2008 - 2013 vortexbox.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

echo ""
echo "Configuring DHCP Server"
echo ""

IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`

cat > /etc/dhcpd.conf <<EOF
ddns-update-style interim;
ignore client-updates;

subnet 192.168.1.0 netmask 255.255.255.0 {

  option routers                  192.168.1.1;
  option subnet-mask              255.255.255.0;
  option nis-domain               "vortexbox.local";
  option domain-name              "vortexbox.local";
  option domain-name-servers      192.168.1.1;
  option time-offset              -18000; # Eastern Standard Time
  option ntp-servers              $IPADDR;
  option tftp-server-name         "$IPADDR";

  range dynamic-bootp 192.168.1.128 192.168.1.254;
  default-lease-time 43200;
  max-lease-time 86400;
}
EOF

yum -y install dhcp
chkconfig --level 2345 dhcpd on

echo "Created /etc/dhcpd.conf and set dhcpd to autostart on reboot."
echo "you can edit /etc/dhcpd.conf and add you own options"
echo ""
