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