coverity appeasement
[minix.git] / commands / update_bootcfg / update_bootcfg.sh
blobdc443ac5f8cdb3504e9f384c684913d90e49b62d
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
10 filter_missing_entries()
12 while read line
14 if ! echo "$line" | grep -s -q 'multiboot'
15 then
16 echo "$line"
17 continue
20 # Check if kernel presents
21 kernel=`echo "$line" | sed -n 's/.*multiboot[[:space:]]*\(\/[^[:space:]]*\).*/\1/p'`
22 if [ ! -r "$kernel" ]
23 then
24 echo "Warning: config contains entry for \"$kernel\" which is missing! Entry skipped." 1>&2
25 else
26 echo "$line"
28 done
31 if [ ! -b "$ROOT" ]
32 then
33 echo root device $ROOT not found
34 exit 1
37 rootdevname=`echo $ROOT | sed 's/\/dev\///'`
39 if [ -r $DEFAULTCFG ]
40 then
41 default_cfg=`cat $DEFAULTCFG`
42 # Substitute variables like $rootdevname
43 echo "$default_cfg" | while read line; do eval echo \"$line\" | filter_missing_entries >> $TMP; done
46 if [ -e /boot/minix_latest -a -d /boot/minix_latest -o -h /boot/minix_latest ]
47 then
48 latest=`basename \`stat -f "%Y" /boot/minix_latest\``
51 [ -d $DIRSBASE ] && for i in `ls $DIRSBASE/`
53 build_name="`basename $i`"
54 if [ "$build_name" != "$latest" ]
55 then
56 echo "menu=Start MINIX 3 ($build_name):load_mods $DIRSBASE/$i/mod*;multiboot $DIRSBASE/$i/kernel rootdevname=$rootdevname" >> /$TMP
58 done
60 [ -r $LOCALCFG ] && cat $LOCALCFG | filter_missing_entries >> $TMP
62 mv $TMP /boot.cfg
64 sync