arm: protect state after signal handler
[minix.git] / commands / update_bootcfg / update_bootcfg.sh
blob33abf6d30517d8191ab88bd46d14d9a7c80dcb88
1 #!/bin/sh
2 set -e
4 ROOT=`printroot -r`
5 DEFAULTCFG=/etc/boot.cfg.default
6 LOCALCFG=/etc/boot.cfg.local
7 TMP=/boot.cfg.temp
8 DIRSBASE=/boot/minix
9 INHERIT="ahci acpi no_apic"
11 filter_entries()
13 # This routine performs three tasks:
14 # - substitute variables in the configuration lines;
15 # - remove multiboot entries that refer to nonexistent kernels;
16 # - adjust the default option for line removal and different files.
17 # The last part is handled by the awk part of the routine.
19 while read line
21 # Substitute variables like $rootdevname and $args
22 line=$(eval echo \"$line\")
24 if ! echo "$line" | grep -sq '^menu=.*multiboot'
25 then
26 echo "$line"
27 continue
30 # Check if the referenced kernel is present
31 kernel=`echo "$line" | sed -n 's/.*multiboot[[:space:]]*\(\/[^[:space:]]*\).*/\1/p'`
32 if [ ! -r "$kernel" ]
33 then
34 echo "Warning: config contains entry for \"$kernel\" which is missing! Entry skipped." 1>&2
35 echo "menu=SKIP"
36 else
37 echo "$line"
39 done | awk '
40 BEGIN {
41 count=1
42 base=0
43 default=0
45 /^menu=SKIP$/ {
46 # A menu entry discarded by the kernel check above
47 skip[count++]=1
48 next
50 /^menu=/ {
51 # A valid menu entry
52 skip[count++]=0
53 print
54 next
56 /^BASE=/ {
57 # The menu count base as passed in by count_entries()
58 sub(/^.*=/,"",$1)
59 base=$1+0
60 next
62 /^default=/ {
63 # The default option
64 # Correct for the menu count base and store for later
65 sub(/^.*=/,"",$1)
66 default=$1+base
67 next
70 # Any other line
71 print
73 END {
74 # If a default was given, correct for removed lines
75 # (do not bother to warn if the default itself is gone)
76 if (default) {
77 for (i = default; i > 0; i--)
78 if (skip[i]) default--;
79 print "default=" default
85 count_entries()
87 echo -n "BASE="; grep -cs '^menu=' "$1"
90 if [ ! -b "$ROOT" ]
91 then
92 echo root device $ROOT not found
93 exit 1
96 rootdevname=`echo $ROOT | sed 's/\/dev\///'`
98 # Construct a list of inherited arguments for boot options to use. Note that
99 # rootdevname must not be passed on this way, as it is changed during setup.
100 args=""
101 for k in $INHERIT; do
102 if sysenv | grep -sq "^$k="; then
103 kv=$(sysenv | grep "^$k=")
104 args="$args $kv"
106 done
108 if [ -r $DEFAULTCFG ]
109 then
110 filter_entries < $DEFAULTCFG >> $TMP
113 if [ -d /boot/minix_latest -o -h /boot/minix_latest ]
114 then
115 latest=`basename \`stat -f "%Y" /boot/minix_latest\``
118 [ -d $DIRSBASE ] && for i in `ls $DIRSBASE/`
120 build_name="`basename $i`"
121 if [ "$build_name" != "$latest" ]
122 then
123 echo "menu=Start MINIX 3 ($build_name):load_mods $DIRSBASE/$i/mod*;multiboot $DIRSBASE/$i/kernel rootdevname=$rootdevname $args" >> $TMP
125 done
127 if [ -r $LOCALCFG ]
128 then
129 # If the local config supplies a "default" option, we assume that this
130 # refers to one of the options in the local config itself. Therefore,
131 # we increase this default by the number of options already present in
132 # the output so far. To this end, count_entries() inserts a special
133 # token that is recognized and filtered out by filter_entries().
134 (count_entries $TMP; cat $LOCALCFG) | filter_entries >> $TMP
137 mv $TMP /boot.cfg
139 sync