xref: /freebsd/libexec/bootpd/ConvOldTab.sh (revision 59e2ff550c448126b988150ce800cdf73bb5103e)
1#!/bin/sh
2#   convert_bootptab	Jeroen.Scheerder@let.ruu.nl 02/25/94
3#	This script can be used to convert bootptab files in old format
4#	to new (termcap-like) bootptab files
5#
6# The old format - real entries are commented out by '###'
7#
8# Old-style bootp files consist of two sections.
9# The first section has two entries:
10# First, a line that specifies the home directory
11# (where boot file paths are relative to)
12
13###/tftpboot
14
15# The next non-empty non-comment line specifies the default bootfile
16
17###no-file
18
19# End of first section - indicated by '%%' at the start of the line
20
21###%%
22
23# The remainder of this file contains one line per client
24# interface with the information shown by the table headings
25# below. The host name is also tried as a suffix for the
26# bootfile when searching the home directory (that is,
27# bootfile.host)
28#
29# Note that htype is always 1, indicating the hardware type Ethernet.
30# Conversion therefore always yields ':ha=ether:'.
31#
32# host	htype	haddr	iaddr	bootfile
33#
34
35###somehost	1	00:0b:ad:01:de:ad	128.128.128.128	dummy
36
37# That's all for the description of the old format.
38# For the new-and-improved format, see bootptab(5).
39
40set -u$DX
41
42case $#
43in	2 )	OLDTAB=$1 ; NEWTAB=$2 ;;
44	* )	echo "Usage: `basename $0` <Input> <Output>"
45		exit 1
46esac
47
48if [ ! -r $OLDTAB ]
49then
50	echo "`basename $0`: $OLDTAB does not exist or is unreadable."
51	exit 1
52fi
53
54if touch $NEWTAB 2> /dev/null
55then
56	:
57else
58	echo "`basename $0`: cannot write to $NEWTAB."
59	exit 1
60fi
61
62
63cat << END_OF_HEADER >> $NEWTAB
64# /etc/bootptab: database for bootp server (/etc/bootpd)
65# This file was generated automagically
66
67# Blank lines and lines beginning with '#' are ignored.
68#
69# Legend:	(see bootptab.5)
70#	first field -- hostname (not indented)
71#	bf -- bootfile
72#	bs -- bootfile size in 512-octet blocks
73#	cs -- cookie servers
74#	df -- dump file name
75#	dn -- domain name
76#	ds -- domain name servers
77#	ef -- extension file
78#	gw -- gateways
79#	ha -- hardware address
80#	hd -- home directory for bootfiles
81#	hn -- host name set for client
82#	ht -- hardware type
83#	im -- impress servers
84#	ip -- host IP address
85#	lg -- log servers
86#	lp -- LPR servers
87#	ns -- IEN-116 name servers
88#	ra -- reply address
89#	rl -- resource location protocol servers
90#	rp -- root path
91#	sa -- boot server address
92#	sm -- subnet mask
93#	sw -- swap server
94#	tc -- template host (points to similar host entry)
95#	td -- TFTP directory
96#	to -- time offset (seconds)
97#	ts -- time servers
98#	vm -- vendor magic number
99#	Tn -- generic option tag n
100#
101# Be careful about including backslashes where they're needed.  Weird (bad)
102# things can happen when a backslash is omitted where one is intended.
103# Also, note that generic option data must be either a string or a
104# sequence of bytes where each byte is a two-digit hex value.
105
106# First, we define a global entry which specifies the stuff every host uses.
107# (Host name lookups are relative to the domain: your.domain.name)
108
109END_OF_HEADER
110
111# Fix up HW addresses in aa:bb:cc:dd:ee:ff and aa-bb-cc-dd-ee-ff style first
112# Then awk our stuff together
113sed -e  's/[:-]//g' < $OLDTAB | \
114nawk 'BEGIN	{ PART = 0 ; FIELD=0 ; BOOTPATH="unset" ; BOOTFILE="unset" }
115	/^%%/	{
116				PART = 1
117				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
118				next
119			}
120	/^$/	{ next }
121	/^#/	{ next }
122		{
123			if ( PART == 0 && FIELD < 2 )
124		  	{
125				if ( FIELD == 0 ) BOOTPATH=$1
126				if ( FIELD == 1 ) BOOTFILE=$1
127				FIELD++
128			}
129		}
130		{
131			if ( PART == 1 )
132			{
133				HOST=$1
134				HA=$3
135				IP=$4
136				BF=$5
137				printf "%s:\\\n\t:tc=.default:\\\n\t:ha=0x%s:\\\n\t:ip=%s:\\\n\t:bf=%s:\n", HOST, HA, IP, BF
138			}
139		}' >> $NEWTAB
140
141exit 0
142