1#!/bin/sh 2# 3# $NetBSD: ConvOldTab.sh,v 1.2 1998/01/09 08:09:01 perry Exp $ 4# 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 8# 9# The old format - real entries are commented out by '###' 10# 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) 15 16###/tftpboot 17 18# The next non-empty non-comment line specifies the default bootfile 19 20###no-file 21 22# End of first section - indicated by '%%' at the start of the line 23 24###%% 25 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) 31# 32# Note that htype is always 1, indicating the hardware type Ethernet. 33# Conversion therefore always yields ':ha=ether:'. 34# 35# host htype haddr iaddr bootfile 36# 37 38###somehost 1 00:0b:ad:01:de:ad 128.128.128.128 dummy 39 40# That's all for the description of the old format. 41# For the new-and-improved format, see bootptab(5). 42 43set -u$DX 44 45case $# 46in 2 ) OLDTAB=$1 ; NEWTAB=$2 ;; 47 * ) echo "Usage: `basename $0` <Input> <Output>" 48 exit 1 49esac 50 51if [ ! -r $OLDTAB ] 52then 53 echo "`basename $0`: $OLDTAB does not exist or is unreadable." 54 exit 1 55fi 56 57if touch $NEWTAB 2> /dev/null 58then 59 : 60else 61 echo "`basename $0`: cannot write to $NEWTAB." 62 exit 1 63fi 64 65 66cat << END_OF_HEADER >> $NEWTAB 67# /etc/bootptab: database for bootp server (/etc/bootpd) 68# This file was generated automagically 69 70# Blank lines and lines beginning with '#' are ignored. 71# 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 103# 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. 108 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) 111 112END_OF_HEADER 113 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 116sed -e 's/[:-]//g' < $OLDTAB | \ 117nawk '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 122 } 123 /^$/ { next } 124 /^#/ { next } 125 { 126 if ( PART == 0 && FIELD < 2 ) 127 { 128 if ( FIELD == 0 ) BOOTPATH=$1 129 if ( FIELD == 1 ) BOOTFILE=$1 130 FIELD++ 131 } 132 } 133 { 134 if ( PART == 1 ) 135 { 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 141 } 142 }' >> $NEWTAB 143 144exit 0 145