13229Spst#!/bin/sh
23229Spst#   convert_bootptab	Jeroen.Scheerder@let.ruu.nl 02/25/94
33229Spst#	This script can be used to convert bootptab files in old format
43229Spst#	to new (termcap-like) bootptab files
53229Spst#
63229Spst# The old format - real entries are commented out by '###'
73229Spst#
83229Spst# Old-style bootp files consist of two sections.
93229Spst# The first section has two entries:
103229Spst# First, a line that specifies the home directory
113229Spst# (where boot file paths are relative to)
123229Spst
133229Spst###/tftpboot
143229Spst
153229Spst# The next non-empty non-comment line specifies the default bootfile
163229Spst
173229Spst###no-file
183229Spst
193229Spst# End of first section - indicated by '%%' at the start of the line
203229Spst
213229Spst###%%
223229Spst
233229Spst# The remainder of this file contains one line per client
243229Spst# interface with the information shown by the table headings
253229Spst# below. The host name is also tried as a suffix for the
263229Spst# bootfile when searching the home directory (that is,
273229Spst# bootfile.host)
283229Spst#
293229Spst# Note that htype is always 1, indicating the hardware type Ethernet.
303229Spst# Conversion therefore always yields ':ha=ether:'.
313229Spst#
323229Spst# host	htype	haddr	iaddr	bootfile
333229Spst#
343229Spst
353229Spst###somehost	1	00:0b:ad:01:de:ad	128.128.128.128	dummy
363229Spst
373229Spst# That's all for the description of the old format.
383229Spst# For the new-and-improved format, see bootptab(5).
393229Spst
403229Spstset -u$DX
413229Spst
423229Spstcase $#
433229Spstin	2 )	OLDTAB=$1 ; NEWTAB=$2 ;;
443229Spst	* )	echo "Usage: `basename $0` <Input> <Output>"
453229Spst		exit 1
463229Spstesac
473229Spst
483229Spstif [ ! -r $OLDTAB ]
493229Spstthen
503229Spst	echo "`basename $0`: $OLDTAB does not exist or is unreadable."
513229Spst	exit 1
523229Spstfi
533229Spst
543229Spstif touch $NEWTAB 2> /dev/null
553229Spstthen
563229Spst	:
573229Spstelse
583229Spst	echo "`basename $0`: cannot write to $NEWTAB."
593229Spst	exit 1
603229Spstfi
613229Spst
623229Spst
633229Spstcat << END_OF_HEADER >> $NEWTAB
643229Spst# /etc/bootptab: database for bootp server (/etc/bootpd)
653229Spst# This file was generated automagically
663229Spst
673229Spst# Blank lines and lines beginning with '#' are ignored.
683229Spst#
693229Spst# Legend:	(see bootptab.5)
703229Spst#	first field -- hostname (not indented)
713229Spst#	bf -- bootfile
723229Spst#	bs -- bootfile size in 512-octet blocks
733229Spst#	cs -- cookie servers
743229Spst#	df -- dump file name
753229Spst#	dn -- domain name
763229Spst#	ds -- domain name servers
773229Spst#	ef -- extension file
783229Spst#	gw -- gateways
793229Spst#	ha -- hardware address
803229Spst#	hd -- home directory for bootfiles
813229Spst#	hn -- host name set for client
823229Spst#	ht -- hardware type
833229Spst#	im -- impress servers
843229Spst#	ip -- host IP address
853229Spst#	lg -- log servers
863229Spst#	lp -- LPR servers
873229Spst#	ns -- IEN-116 name servers
883229Spst#	ra -- reply address
893229Spst#	rl -- resource location protocol servers
903229Spst#	rp -- root path
913229Spst#	sa -- boot server address
923229Spst#	sm -- subnet mask
933229Spst#	sw -- swap server
943229Spst#	tc -- template host (points to similar host entry)
953229Spst#	td -- TFTP directory
963229Spst#	to -- time offset (seconds)
973229Spst#	ts -- time servers
983229Spst#	vm -- vendor magic number
993229Spst#	Tn -- generic option tag n
1003229Spst#
1013229Spst# Be careful about including backslashes where they're needed.  Weird (bad)
1023229Spst# things can happen when a backslash is omitted where one is intended.
1033229Spst# Also, note that generic option data must be either a string or a
1043229Spst# sequence of bytes where each byte is a two-digit hex value.
1053229Spst
1063229Spst# First, we define a global entry which specifies the stuff every host uses.
1073229Spst# (Host name lookups are relative to the domain: your.domain.name)
1083229Spst
1093229SpstEND_OF_HEADER
1103229Spst
1113229Spst# Fix up HW addresses in aa:bb:cc:dd:ee:ff and aa-bb-cc-dd-ee-ff style first
1123229Spst# Then awk our stuff together
1133229Spstsed -e  's/[:-]//g' < $OLDTAB | \
1143229Spstnawk 'BEGIN	{ PART = 0 ; FIELD=0 ; BOOTPATH="unset" ; BOOTFILE="unset" }
1153229Spst	/^%%/	{
1163229Spst				PART = 1
1173229Spst				printf ".default:\\\n\t:ht=ether:\\\n\t:hn:\\\n\t:dn=your.domain.name:\\\n\t:ds=your,dns,servers:\\\n\t:sm=255.255.0.0:\\\n\t:hd=%s:\\\n\t:rp=%s:\\\n\t:td=%s:\\\n\t:bf=%s:\\\n\t:to=auto:\n\n", BOOTPATH, BOOTPATH, BOOTPATH, BOOTFILE
1183229Spst				next
1193229Spst			}
1203229Spst	/^$/	{ next }
1213229Spst	/^#/	{ next }
1223229Spst		{
1233229Spst			if ( PART == 0 && FIELD < 2 )
1243229Spst		  	{
1253229Spst				if ( FIELD == 0 ) BOOTPATH=$1
1263229Spst				if ( FIELD == 1 ) BOOTFILE=$1
1273229Spst				FIELD++
1283229Spst			}
1293229Spst		}
1303229Spst		{
1313229Spst			if ( PART == 1 )
1323229Spst			{
1333229Spst				HOST=$1
1343229Spst				HA=$3
1353229Spst				IP=$4
1363229Spst				BF=$5
1373229Spst				printf "%s:\\\n\t:tc=.default:\\\n\t:ha=0x%s:\\\n\t:ip=%s:\\\n\t:bf=%s:\n", HOST, HA, IP, BF
1383229Spst			}
1393229Spst		}' >> $NEWTAB
1403229Spst
1413229Spstexit 0
142