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