#!/bin/sh -e
#  This file is called when the domain name is changed, to change any
#  dhcpd configuration files affected.
#
#  The first argument is the new domain name,

#  Copyright 2008, One Laptop per Child
#  Authors: John Watlington, Martin Langhoff
#  License: GPLv2

#  This is the name of the service (for stopping and restarting)
SERVICE_NAME=dhcpd

#  This is a config file related to this service which will have
#  the domain name globally replaced inside it
CONFIG_LIST="/etc/dhcpd-xs.conf"

#  This is the suffix which original versions of modified files will have
BACKUP_SUFFIX=old

new_name=$1

for config in $CONFIG_LIST;
do
    if [ -e $config.in ]; then
	if [ -e $config ]; then
	    mv $config $config.$BACKUP_SUFFIX
	fi
	sed -e s/@@BASEDNSNAME@@/$new_name/ $config.in > $config ;
    else
	echo WARNING: Skipped $config - template file is missing!
    fi
done


## for some strange reason - /sbin/service                                                                                       
## shows a reverse heisenbug - works only when                                                                                   
## we call it with bash -x                                                                                                       
#     service $SERVICE_NAME condrestart                                                                                          
## so instead we use...                                                                                                          
/etc/init.d/$SERVICE_NAME condrestart
