#!/bin/sh -e
#  This file is called when the domain name is changed, to change any
#  idmgr 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=idmgr

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

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

short_host=`hostname -s`
new_name=$short_host.$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/@@BASEDNSNAME2@@/$new_name/ $config.in > $config ;
    else
	echo WARNING: Skipped $config - template file is missing!
    fi
done

# Since for the community edition, we don't really expect all modules to be present
#   Just exit, and expect the user to do a restart

exit 0


