#!/bin/tcsh -f
# JLdL 18Apr08.
#
# Copyright (C) 2008 by Jorge L. deLyra <delyra@fma.if.usp.br>.
# This program may be copied and/or distributed freely. See the
# _ terms and conditions in /usr/share/doc/<package>/copyright.
#
# This script may be executed remotely by ssh from another system;
# _ it updates the IP number in the hosts database of the master
# _ NIS server, as well as the binary NIS maps, of a given client
# _ registered in the dynahostnis service.
#
# Get the remote FQDN from the command line.
set rfqdn = "$1"
#
# Get the remote IP address from the command line.
set raddr = "$2"
#
# Define a variable with the TAB character.
set tab = "`echo '\t'`"
#
# Define a grep target to match a generic numerical IP address.
set iptrg = '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
#
# Define the hosts file.
set hfile = /etc/hosts
#
# Update the hosts file.
echo Updating the $hfile file...
cat $hfile | \
sed -e "s|^$iptrg$tab$rfqdn|$raddr$tab$rfqdn|g" \
    >! $hfile.DYNAHOSTNIS
cp -f $hfile.DYNAHOSTNIS $hfile
#
# Update the binary NIS maps.
echo Updating the binary NIS maps...
#
# Go to the directory.
cd /var/yp
#
# Update the maps.
make
#
# Go back.
cd -
