]> git.lizzy.rs Git - plan9front.git/blobdiff - rc/bin/cpurc
cpurc: handle case with missing /net/ipselftab
[plan9front.git] / rc / bin / cpurc
index f6bd2eb563cb2d42a7fff0461bacf22bcca9676d..c7198b8275313377728173e7935f7a701b35d246 100755 (executable)
@@ -7,7 +7,9 @@ for(i in m i P S t u '$')
        bind -a '#'^$i /dev >/dev/null >[2=1]
 
 mount -qb /srv/cons /dev
-mount -qa /srv/usb /dev
+
+# usb listener
+nusbrc
 
 # mount points
 mntgen -s slashn && chmod 666 /srv/slashn
@@ -15,60 +17,67 @@ mntgen -s slashn && chmod 666 /srv/slashn
 # name translation, cs sets /dev/sysname
 ndb/cs
 sysname=`{cat /dev/sysname}
-
-# parallelism for mk
-NPROC = `{wc -l </dev/sysstat}
-
-if (~ $#sysname 0 || ~ $sysname '') {
-       sysname = cirno                 # default
+if (~ $#sysname 0 || ~ $sysname ''){
+       sysname=cirno                   # default
        echo -n $sysname >/dev/sysname
 }
 prompt=($sysname^'# ' '        ')
 
+# parallelism for mk
+NPROC=`{wc -l </dev/sysstat}
+
 # cpu-specific startup
 if(test -e /cfg/$sysname/cpurc)
        . /cfg/$sysname/cpurc
 
-# start up internet if we don't already have an address
-if(! grep u /net/ipselftab | grep -sv 127.0.0.1)
-       ip/ipconfig
+# automatic ip address setup
+if(test -r /net/ipselftab){
+       if(! grep u /net/ipselftab | grep -sv 127.0.0.1){
+               ether=`{ndb/query sys $sysname ether}
+               if(~ $#ether 1){
+                       # try /lib/ndb first, then do dhcp
+                       ip/ipconfig -N >[2]/dev/null || ip/ipconfig
+               }
+               rm -f /env/ether
+       }
+}
 
-# if we're not a server, start a dns resolver
-if(! test -e /srv/dns)
+if(! test -e /net/dns)
        ndb/dns -r
 
-# If you are on an auth server, start these before listening:
-#
-auth/keyfs -wp -m /mnt/keys /adm/keys >/dev/null >[2=1]
-auth/cron >>/sys/log/cron >[2=1] &
-#
-# also rename some files:
-#
-# if(! test -e /rc/bin/service.auth/tcp567){
-#      mv /rc/bin/service.auth/authsrv.il566 /rc/bin/service.auth/il566
-#      mv /rc/bin/service.auth/authsrv.tcp567 /rc/bin/service.auth/tcp567
-#      mv /rc/bin/service/il566 /rc/bin/service/_il566
-#      mv /rc/bin/service/tcp567 /rc/bin/service/_tcp567
-# }
-
-# start listeners
-aux/listen -q -t /rc/bin/service.auth -d /rc/bin/service tcp
+if(! ps|grep -s timesync){
+       if(~ $#ntp 0)
+               . <{ndb/ipquery sys $sysname ntp | sed 's, +,\n,g'}
+       if(~ $#ntp 0)
+               ntp=pool.ntp.org
+       aux/timesync -n $ntp
+       sleep 2
+}
 
-if(! ps|grep -s timesync) {
-       aux/timesync -n pool.ntp.org
-       if (test -e '#r/rtc') @ {
-               sleep 10                        # let timesync correct the time
-               awk '{print $1}' /dev/time >'#r/rtc'    # fix hw clock
-       } &
+if(~ $#auth 0){
+       auth=`{ndb/query sys $sysname auth}
+       . <{ndb/ipquery sys $sysname auth | sed 's, +,\n,g'}
 }
+switch($auth){
+case `{        echo $sysname; ndb/query sys $sysname dom
+       if(test -r /net/ipselftab){
+       for(i in `{awk '/u\ *$/{print $1}' /net/ipselftab}){
+               echo $i; ndb/ipquery ip $i dom; ndb/ipquery ip $i sys
+       } | sed 's,[^ ]+=,,g'}}
+       # cpu+auth server
+       auth/keyfs -wp -m /mnt/keys /adm/keys
+       aux/listen -q -t /rc/bin/service.auth -d /rc/bin/service tcp
+case *
+       # cpu server
+       aux/listen -q -d /rc/bin/service tcp
+}
+
+if(test -f /dev/apm)
+       aux/apm
 
-# cpu-specific late startup
 if(test -e /cfg/$sysname/cpustart)
        . /cfg/$sysname/cpustart
 
 # mode of /proc/*/ctl is inherited across rfork, and sets modes on
 # other /proc files, such as note, so let listen be killed.
-dontkill '^(ipconfig|factotum|mntgen|venti|kfs|cwfs.*|cs|dns|reboot)$'
-
-# echo `{date} $sysname >>/sys/log/boot
-exit ''
+dontkill '^(ipconfig|factotum|mntgen|venti|kfs|cfs|cwfs.*|9660srv|dossrv|paqfs|cs|dns|reboot|usbd|kb|disk|ether)$'