#!/bin/rc

# rename old-hostname new-hostname

path=(/etc /usr/local/etc $path)

myname=`{basename $0}

fn usage {
	echo 'usage: '$myname^' old-hostname new-hostname' >[2=1]
	exit 1
}

! ~ $#'*' 2 && usage

echo $myname^: 'WARNING - this is not for the handyman,  professional installation only.' >[2=1]

! ~ `hostname perle && {
	echo $myname^: 'This needs to be run on perle.'
	exit 1
}

fn rsh {
	/usr/ucb/rsh $*
}

old=$1
new=$2

edcmd='1,$s/'$old^/$new^/gp'
w
q
'
rcscomment=$old^' renamed to be '$new^.

~ $new ???????* && echo $myname^': Warning: "'$new'"''s name is too long for a DECnet node name.' >[2=1]

# fix stuff in /etc

for (i in /etc/^(hosts hosts.equiv offered))
	echo $edcmd | /udir/boyd/hacks/edit $i $rcscomment || exit 1

# fix /prl/machines and bereski's database

for (i in /prl/machines /prl/distribute/DataBase/Clients) {
	@{ cd $i && mv $old $new} || exit 1
}

wsField -n $new -f IpSName -v $new

if (! ~ `{wsField -n $new -f IpSName} $new) {
	echo $myname^': wsField database problem with "'$new^'".'
	exit 1
}

# fix /proj/pmaxes

mkdir /tmp/$old^.$pid && @{ cd /tmp/$old^.$pid && getpackage /proj/pmaxes/$old }

mkdir /tmp/$new^.$pid && @{ cd /tmp/$new^.$pid && ppa i $new && getpackage /proj/pmaxes/$new }

cp /tmp/$old^.$pid^/* /tmp/$new.$pid || exit 1

@{cd /tmp/$old^.$pid && unlockpackage /proj/pmaxes/$old }

@{cd /tmp/$new^.$pid && shippackage /proj/pmaxes/$new && unlockpackage /proj/pmaxes/$new }

# cd /tmp && rm -fr $old^.$pid $new^.$pid

echo $edcmd | rsh $new 'rm -f /etc/RCS/rc.local,v ; /udir/boyd/hacks/edit /etc/rc.local'

# fix the DNS

rsh mother /udir/boyd/hacks/rename-dns $old $new

# fix the diskless root file-system's etc

#rsh mother 'test -d /dl/C/4.2A/'$old^' && cd /dl/C/4.2A && mv '$old^' '$new

#rsh mother 'test -d /dl/C/4.2A/'$new^' && addnode '$new^' -s /dl/C/4.2A/'$new^'/etc/netblk.mother.o -t /dl/C/4.2A/'$new^'/vmunix -D /dl/C/4.2A/'$new^'/var/adm/vmcore'

# .rhosts on the dump servers

for (i in kate bucket) {
	echo $edcmd | rsh $i /udir/boyd/hacks/edit /.rhosts
}

# fix mountd braindamage

for (i in perle mother nacre prlp24 bucket)
	rsh $i 'test -r /etc/exports && touch /etc/exports'

echo Replicating net to $new^. >[1=2]

replicate net $new

echo Replicating net to all. >[1=2]

replicate net all


© 1998, Boyd Roberts: boyd@fr.inter.net