1#!/bin/sh 2set -e 3 4ROOT=`printroot -r` 5DEFAULTCFG=/etc/boot.cfg.default 6LOCALCFG=/etc/boot.cfg.local 7TMP=/boot.cfg.temp 8DIRSBASE=/boot/minix 9INHERIT="ahci acpi no_apic nobeep" 10 11filter_entries() 12{ 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. 18 19 while read line 20 do 21 # Substitute variables like $rootdevname and $args 22 line=$(eval echo \"$line\") 23 24 if ! echo "$line" | grep -sq '^menu=.*multiboot' 25 then 26 echo "$line" 27 continue 28 fi 29 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" 38 fi 39 done | awk ' 40 BEGIN { 41 count=1 42 base=0 43 default=0 44 } 45 /^menu=SKIP$/ { 46 # A menu entry discarded by the kernel check above 47 skip[count++]=1 48 next 49 } 50 /^menu=/ { 51 # A valid menu entry 52 skip[count++]=0 53 print 54 next 55 } 56 /^BASE=/ { 57 # The menu count base as passed in by count_entries() 58 sub(/^.*=/,"",$1) 59 base=$1+0 60 next 61 } 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 68 } 69 { 70 # Any other line 71 print 72 } 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 80 } 81 } 82 ' 83} 84 85count_entries() 86{ 87 echo -n "BASE="; grep -cs '^menu=' "$1" 88} 89 90if [ ! -b "$ROOT" ] 91then 92 echo root device $ROOT not found 93 exit 1 94fi 95 96rootdevname=`echo $ROOT | sed 's/\/dev\///'` 97 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. 100args="" 101for k in $INHERIT; do 102 if sysenv | grep -sq "^$k="; then 103 kv=$(sysenv | grep "^$k=") 104 args="$args $kv" 105 fi 106done 107 108if [ -r $DEFAULTCFG ] 109then 110 filter_entries < $DEFAULTCFG >> $TMP 111fi 112 113if [ -d /boot/minix_latest -o -h /boot/minix_latest ] 114then 115 latest=`basename \`stat -f "%Y" /boot/minix_latest\`` 116fi 117 118[ -d $DIRSBASE ] && for i in `ls $DIRSBASE/` 119do 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 124 fi 125done 126 127if [ -r $LOCALCFG ] 128then 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 135fi 136 137mv $TMP /boot.cfg 138 139sync 140