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