]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fshalt
nusbrc: delect lenovo camera
[plan9front.git] / rc / bin / fshalt
1 #!/bin/rc
2 # fshalt [-r] - sync (flush) and, if possible, halt all file servers
3 #       and optionally reboot
4 rfork en
5 reboot=no
6 scram=no
7 switch ($#*) {
8 case 0
9 case 1
10         reboot=yes
11 case *
12         echo usage: $0 '[-r]' >[1=2]
13         exit usage
14 }
15
16 path=(/bin)
17 builtin cd /
18 bind -c '#s' /srv
19 bind '#p' /proc
20
21 unmount /mnt/consoles >[2]/dev/null
22 kill consolefs | rc                     # don't compete with /mnt/consoles
23 sleep 1
24
25 c=`{ls /srv/cwfs*cmd >[2]/dev/null}
26 h=`{ls /srv/hjfs*cmd >[2]/dev/null}
27
28 # for scram, don't scram other systems
29 bind -b '#P' /dev
30 if(! ~ $reboot yes){
31         if (test -e '#P'/apm)
32                 scram=yes
33         if (test -e '#P'/acpitbls -a -e '#P'/iow)
34                 scram=yes
35 }
36
37 # halting (binaries we run can't be on the fs we're halting)
38 ramfs
39 builtin cd /tmp
40 cp /bin/echo /tmp
41 mkdir /tmp/lib
42 cp /rc/lib/rcmain /tmp/lib
43 cp /bin/ns /tmp
44 cp /bin/rc /tmp
45 cp /bin/sed /tmp
46 cp /bin/sleep /tmp
47 cp /bin/scram /tmp
48 cp /bin/test /tmp
49 bind /tmp /rc
50 bind /tmp /bin
51
52 # put this in a shell function so this rc script doesn't get read
53 # when it's no longer accessible
54 fn x {
55         echo
56         echo -n halting...
57         for (i in $c $h)
58                 echo halt >>$i
59         for (i in $c $h){
60                 echo -n $i...
61                 while(test -e $i)
62                         sleep 1
63         }
64         echo
65         echo done halting
66
67         if (~ $reboot yes) {
68                 echo rebooting...
69                 echo reboot >'#c/reboot'
70         }
71         if (~ $scram yes){
72                 scram
73                 echo 'It''s now safe to turn off your computer'
74         }
75 }
76
77 x