ConvOldTab.sh revision 1.1
11.1Sgwr#!/bin/sh 21.1Sgwr# convert_bootptab Jeroen.Scheerder@let.ruu.nl 02/25/94 31.1Sgwr# This script can be used to convert bootptab files in old format 41.1Sgwr# to new (termcap-like) bootptab files 51.1Sgwr# 61.1Sgwr# The old format - real entries are commented out by '###' 71.1Sgwr# 81.1Sgwr# Old-style bootp files consist of two sections. 91.1Sgwr# The first section has two entries: 101.1Sgwr# First, a line that specifies the home directory 111.1Sgwr# (where boot file paths are relative to) 121.1Sgwr 131.1Sgwr###/tftpboot 141.1Sgwr 151.1Sgwr# The next non-empty non-comment line specifies the default bootfile 161.1Sgwr 171.1Sgwr###no-file 181.1Sgwr 191.1Sgwr# End of first section - indicated by '%%' at the start of the line 201.1Sgwr 211.1Sgwr###%% 221.1Sgwr 231.1Sgwr# The remainder of this file contains one line per client 241.1Sgwr# interface with the information shown by the table headings 251.1Sgwr# below. The host name is also tried as a suffix for the 261.1Sgwr# bootfile when searching the home directory (that is, 271.1Sgwr# bootfile.host) 281.1Sgwr# 291.1Sgwr# Note that htype is always 1, indicating the hardware type Ethernet. 301.1Sgwr# Conversion therefore always yields ':ha=ether:'. 311.1Sgwr# 321.1Sgwr# host htype haddr iaddr bootfile 331.1Sgwr# 341.1Sgwr 351.1Sgwr###somehost 1 00:0b:ad:01:de:ad 128.128.128.128 dummy 361.1Sgwr 371.1Sgwr# That's all for the description of the old format. 381.1Sgwr# For the new-and-improved format, see bootptab(5). 391.1Sgwr 401.1Sgwrset -u$DX 411.1Sgwr 421.1Sgwrcase $# 431.1Sgwrin 2 ) OLDTAB=$1 ; NEWTAB=$2 ;; 441.1Sgwr * ) echo "Usage: `basename $0` <Input> <Output>" 451.1Sgwr exit 1 461.1Sgwresac 471.1Sgwr 481.1Sgwrif [ ! -r $OLDTAB ] 491.1Sgwrthen 501.1Sgwr echo "`basename $0`: $OLDTAB does not exist or is unreadable." 511.1Sgwr exit 1 521.1Sgwrfi 531.1Sgwr 541.1Sgwrif touch $NEWTAB 2> /dev/null 551.1Sgwrthen 561.1Sgwr : 571.1Sgwrelse 581.1Sgwr echo "`basename $0`: cannot write to $NEWTAB." 591.1Sgwr exit 1 601.1Sgwrfi 611.1Sgwr 621.1Sgwr 631.1Sgwrcat << END_OF_HEADER >> $NEWTAB 641.1Sgwr# /etc/bootptab: database for bootp server (/etc/bootpd) 651.1Sgwr# This file was generated automagically 661.1Sgwr 671.1Sgwr# Blank lines and lines beginning with '#' are ignored. 681.1Sgwr# 691.1Sgwr# Legend: (see bootptab.5) 701.1Sgwr# first field -- hostname (not indented) 711.1Sgwr# bf -- bootfile 721.1Sgwr# bs -- bootfile size in 512-octet blocks 731.1Sgwr# cs -- cookie servers 741.1Sgwr# df -- dump file name 751.1Sgwr# dn -- domain name 761.1Sgwr# ds -- domain name servers 771.1Sgwr# ef -- extension file 781.1Sgwr# gw -- gateways 791.1Sgwr# ha -- hardware address 801.1Sgwr# hd -- home directory for bootfiles 811.1Sgwr# hn -- host name set for client 821.1Sgwr# ht -- hardware type 831.1Sgwr# im -- impress servers 841.1Sgwr# ip -- host IP address 851.1Sgwr# lg -- log servers 861.1Sgwr# lp -- LPR servers 871.1Sgwr# ns -- IEN-116 name servers 881.1Sgwr# ra -- reply address 891.1Sgwr# rl -- resource location protocol servers 901.1Sgwr# rp -- root path 911.1Sgwr# sa -- boot server address 921.1Sgwr# sm -- subnet mask 931.1Sgwr# sw -- swap server 941.1Sgwr# tc -- template host (points to similar host entry) 951.1Sgwr# td -- TFTP directory 961.1Sgwr# to -- time offset (seconds) 971.1Sgwr# ts -- time servers 981.1Sgwr# vm -- vendor magic number 991.1Sgwr# Tn -- generic option tag n 1001.1Sgwr# 1011.1Sgwr# Be careful about including backslashes where they're needed. Weird (bad) 1021.1Sgwr# things can happen when a backslash is omitted where one is intended. 1031.1Sgwr# Also, note that generic option data must be either a string or a 1041.1Sgwr# sequence of bytes where each byte is a two-digit hex value. 1051.1Sgwr 1061.1Sgwr# First, we define a global entry which specifies the stuff every host uses. 1071.1Sgwr# (Host name lookups are relative to the domain: your.domain.name) 1081.1Sgwr 1091.1SgwrEND_OF_HEADER 1101.1Sgwr 1111.1Sgwr# Fix up HW addresses in aa:bb:cc:dd:ee:ff and aa-bb-cc-dd-ee-ff style first 1121.1Sgwr# Then awk our stuff together 1131.1Sgwrsed -e 's/[:-]//g' < $OLDTAB | \ 1141.1Sgwrnawk 'BEGIN { PART = 0 ; FIELD=0 ; BOOTPATH="unset" ; BOOTFILE="unset" } 1151.1Sgwr /^%%/ { 1161.1Sgwr PART = 1 1171.1Sgwr 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 1181.1Sgwr next 1191.1Sgwr } 1201.1Sgwr /^$/ { next } 1211.1Sgwr /^#/ { next } 1221.1Sgwr { 1231.1Sgwr if ( PART == 0 && FIELD < 2 ) 1241.1Sgwr { 1251.1Sgwr if ( FIELD == 0 ) BOOTPATH=$1 1261.1Sgwr if ( FIELD == 1 ) BOOTFILE=$1 1271.1Sgwr FIELD++ 1281.1Sgwr } 1291.1Sgwr } 1301.1Sgwr { 1311.1Sgwr if ( PART == 1 ) 1321.1Sgwr { 1331.1Sgwr HOST=$1 1341.1Sgwr HA=$3 1351.1Sgwr IP=$4 1361.1Sgwr BF=$5 1371.1Sgwr printf "%s:\\\n\t:tc=.default:\\\n\t:ha=0x%s:\\\n\t:ip=%s:\\\n\t:bf=%s:\n", HOST, HA, IP, BF 1381.1Sgwr } 1391.1Sgwr }' >> $NEWTAB 1401.1Sgwr 1411.1Sgwrexit 0 142