shithub: riscv

ref: c3867623ae93eca77ba6e4f3d851240442f02caf
dir: /sys/src/9/boot/net.rc/

View raw version
#!/bin/rc

fn confignet{
	# get primary default interface if not specified
	if(~ $#* 0){
		e=/net/ether*
		if(! ~ $e '/net/ether*')
			*=(ether $e(1))
	}

	# setup wifi encryption if any
	if(~ $1 ether && ~ $service terminal && test -x /bin/aux/wpa){
		if(grep -s '^status: need authentication' $2/ifstats >[2]/dev/null){
			aux/wpa -p $2
		}
	}

	must ip/ipconfig -p $*
	if(~ $#fs 0)
		fs=`{awk -F'=' '/^[ 	]*fs=/{print $2}' /net/ndb}
	if(~ $#auth 0)
		auth=`{awk -F'=' '/^[ 	]*auth=/{print $2}' /net/ndb}
	if(~ $#fs 0)
		ask fs ' address is? ' $auth(1)
	if(~ $#auth 0)
		ask auth ' address is? ' $fs(1)

	# resolve dns names
	if(test -x /bin/ndb/dnsgetip){
		for(i in fs auth secstore){
			x=`{for(x in $$i) ndb/dnsgetip -a $x}
			~ $#x 0 || $i=$x
		}
	}

	# set bootstrap authservers for factotum
	if(! ~ $#auth 0){
		grep -v '^[ 	]*auth=' /net/ndb >/env/x
		cat /env/x <{echo '	auth='^$auth^'
'} >/net/ndb
		rm /env/x
	}
}

fn connecttcp{
	while(! ~ $#fs 0 && ! srv -q tcp!$fs(1)^!564 boot)
		fs=$fs(2-);
	fs=$fs(1)
}

fn connectil{
	while(! ~ $#fs 0 && ! srv -q il!$fs(1)^!17008 boot)
		fs=$fs(2-);
	fs=$fs(1)
}

mtcp=(confignet connecttcp)
mil=(confignet connectil)
mt=(mtcp mil $mt)