ConvOldTab.sh revision 3229
1187517Sgonzo#!/bin/sh
2187517Sgonzo#   convert_bootptab	Jeroen.Scheerder@let.ruu.nl 02/25/94
3187517Sgonzo#	This script can be used to convert bootptab files in old format
4187517Sgonzo#	to new (termcap-like) bootptab files
5187517Sgonzo#
6187517Sgonzo# The old format - real entries are commented out by '###'
7187517Sgonzo#
8187517Sgonzo# Old-style bootp files consist of two sections.
9187517Sgonzo# The first section has two entries:
10187517Sgonzo# First, a line that specifies the home directory
11187517Sgonzo# (where boot file paths are relative to)
12187517Sgonzo
13187517Sgonzo###/tftpboot
14187517Sgonzo
15187517Sgonzo# The next non-empty non-comment line specifies the default bootfile
16187517Sgonzo
17187517Sgonzo###no-file
18187517Sgonzo
19187517Sgonzo# End of first section - indicated by '%%' at the start of the line
20187517Sgonzo
21187517Sgonzo###%%
22187517Sgonzo
23187517Sgonzo# The remainder of this file contains one line per client
24187517Sgonzo# interface with the information shown by the table headings
25187517Sgonzo# below. The host name is also tried as a suffix for the
26187517Sgonzo# bootfile when searching the home directory (that is,
27187517Sgonzo# bootfile.host)
28187517Sgonzo#
29187517Sgonzo# Note that htype is always 1, indicating the hardware type Ethernet.
30187517Sgonzo# Conversion therefore always yields ':ha=ether:'.
31187517Sgonzo#
32187517Sgonzo# host	htype	haddr	iaddr	bootfile
33187517Sgonzo#
34187517Sgonzo
35187517Sgonzo###somehost	1	00:0b:ad:01:de:ad	128.128.128.128	dummy
36187517Sgonzo
37187517Sgonzo# That's all for the description of the old format.
38187517Sgonzo# For the new-and-improved format, see bootptab(5).
39187517Sgonzo
40187517Sgonzoset -u$DX
41199497Sgonzo
42187517Sgonzocase $#
43187517Sgonzoin	2 )	OLDTAB=$1 ; NEWTAB=$2 ;;
44187517Sgonzo	* )	echo "Usage: `basename $0` <Input> <Output>"
45221257Sadrian		exit 1
46187517Sgonzoesac
47188883Sgonzo
48188883Sgonzoif [ ! -r $OLDTAB ]
49188883Sgonzothen
50188883Sgonzo	echo "`basename $0`: $OLDTAB does not exist or is unreadable."
51188883Sgonzo	exit 1
52188883Sgonzofi
53188883Sgonzo
54187517Sgonzoif touch $NEWTAB 2> /dev/null
55187517Sgonzothen
56212413Savg	:
57187517Sgonzoelse
58187517Sgonzo	echo "`basename $0`: cannot write to $NEWTAB."
59187517Sgonzo	exit 1
60187517Sgonzofi
61187517Sgonzo
62187517Sgonzo
63187517Sgonzocat << END_OF_HEADER >> $NEWTAB
64187517Sgonzo# /etc/bootptab: database for bootp server (/etc/bootpd)
65187517Sgonzo# This file was generated automagically
66187517Sgonzo
67187517Sgonzo# Blank lines and lines beginning with '#' are ignored.
68187517Sgonzo#
69187517Sgonzo# Legend:	(see bootptab.5)
70187517Sgonzo#	first field -- hostname (not indented)
71187517Sgonzo#	bf -- bootfile
72187517Sgonzo#	bs -- bootfile size in 512-octet blocks
73187517Sgonzo#	cs -- cookie servers
74187517Sgonzo#	df -- dump file name
75192822Sgonzo#	dn -- domain name
76192822Sgonzo#	ds -- domain name servers
77187517Sgonzo#	ef -- extension file
78192822Sgonzo#	gw -- gateways
79187517Sgonzo#	ha -- hardware address
80187517Sgonzo#	hd -- home directory for bootfiles
81187517Sgonzo#	hn -- host name set for client
82187517Sgonzo#	ht -- hardware type
83187517Sgonzo#	im -- impress servers
84187517Sgonzo#	ip -- host IP address
85187517Sgonzo#	lg -- log servers
86192822Sgonzo#	lp -- LPR servers
87192822Sgonzo#	ns -- IEN-116 name servers
88187517Sgonzo#	ra -- reply address
89187517Sgonzo#	rl -- resource location protocol servers
90192822Sgonzo#	rp -- root path
91187517Sgonzo#	sa -- boot server address
92187517Sgonzo#	sm -- subnet mask
93187517Sgonzo#	sw -- swap server
94187517Sgonzo#	tc -- template host (points to similar host entry)
95187517Sgonzo#	td -- TFTP directory
96187517Sgonzo#	to -- time offset (seconds)
97187517Sgonzo#	ts -- time servers
98187517Sgonzo#	vm -- vendor magic number
99187517Sgonzo#	Tn -- generic option tag n
100187517Sgonzo#
101187517Sgonzo# Be careful about including backslashes where they're needed.  Weird (bad)
102187517Sgonzo# things can happen when a backslash is omitted where one is intended.
103187517Sgonzo# Also, note that generic option data must be either a string or a
104187517Sgonzo# sequence of bytes where each byte is a two-digit hex value.
105187517Sgonzo
106187517Sgonzo# First, we define a global entry which specifies the stuff every host uses.
107187517Sgonzo# (Host name lookups are relative to the domain: your.domain.name)
108187517Sgonzo
109187517SgonzoEND_OF_HEADER
110191837Sgonzo
111191837Sgonzo# Fix up HW addresses in aa:bb:cc:dd:ee:ff and aa-bb-cc-dd-ee-ff style first
112191837Sgonzo# Then awk our stuff together
113191837Sgonzosed -e  's/[:-]//g' < $OLDTAB | \
114191837Sgonzonawk 'BEGIN	{ PART = 0 ; FIELD=0 ; BOOTPATH="unset" ; BOOTFILE="unset" }
115191837Sgonzo	/^%%/	{
116191837Sgonzo				PART = 1
117191837Sgonzo				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
118191837Sgonzo				next
119191837Sgonzo			}
120187517Sgonzo	/^$/	{ next }
121187517Sgonzo	/^#/	{ next }
122187517Sgonzo		{
123187517Sgonzo			if ( PART == 0 && FIELD < 2 )
124187517Sgonzo		  	{
125187517Sgonzo				if ( FIELD == 0 ) BOOTPATH=$1
126187517Sgonzo				if ( FIELD == 1 ) BOOTFILE=$1
127187517Sgonzo				FIELD++
128187517Sgonzo			}
129187517Sgonzo		}
130187517Sgonzo		{
131187517Sgonzo			if ( PART == 1 )
132187517Sgonzo			{
133187517Sgonzo				HOST=$1
134187517Sgonzo				HA=$3
135187517Sgonzo				IP=$4
136187517Sgonzo				BF=$5
137187517Sgonzo				printf "%s:\\\n\t:tc=.default:\\\n\t:ha=0x%s:\\\n\t:ip=%s:\\\n\t:bf=%s:\n", HOST, HA, IP, BF
138187517Sgonzo			}
139187517Sgonzo		}' >> $NEWTAB
140187517Sgonzo
141187517Sgonzoexit 0
142187517Sgonzo