#!tcl
#
# pkti - check system.ini for installed netcards
#      - modify netcard statement if necessary
#      - ASSUMES pkt has run previously
#
if {$argc != 2} {
    error "usage: pkti adapter unit"
}
set reboot 1
set a [lindex $argv 0]
set u [lindex $argv 1]
set infile $env(windir)\\system.ini
#
# check adapter
#
set f [open $infile r]
set pat "netcard$u=$a"
 
while {[gets $f line] >= 0} {
    if [string match $pat $line] {
        set reboot 0
        break
    }
}
close $f
if {$reboot == 0} {
    error "OK"
}     
#
# specified netcard statement not found, so add it
#
set f [open $infile r]
set w [open "temp.1" w] 
set pat "netcard$u="
 
while {[gets $f line] >= 0} {
    if [regexp $pat $line] {
        set line "netcard$u=$a"
        puts -nonewline $w $line
        continue
    }
    puts -nonewline $w $line
}
close $f
close $w
#
# copy temp.1 to system.ini
#
set f [open "temp.1" r]
set w [open $infile w] 
while {[gets $f line] >= 0} {
    puts -nonewline $w $line
}
close $f
close $w
echo
error "ERROR"
