]> Zhao Yanbai Git Server - minix.git/commitdiff
update_bootcfg improvements.
authorEvgeniy Ivanov <lolkaantimat@gmail.com>
Thu, 16 Feb 2012 13:38:38 +0000 (17:38 +0400)
committerBen Gras <ben@minix3.org>
Thu, 15 Mar 2012 19:25:04 +0000 (20:25 +0100)
- Fix a glitch (don't glob '*' in for).
- update_bootcfg should be a /bin command.
- update_bootcfg should not add menu entries for missing kernels.

commands/Makefile
commands/update_bootcfg/Makefile [new file with mode: 0644]
commands/update_bootcfg/update_bootcfg.sh [new file with mode: 0755]
tools/Makefile
tools/update_bootcfg.sh [deleted file]

index 3d1d1d54833c6cfeee1c0b206987dd99e6d38bcb..6d82d86714081193f9697d790896fc5539d0e519 100644 (file)
@@ -33,7 +33,7 @@ SUBDIR=       add_route arp ash at awk \
        unstack update uud uue version vol wc \
        whereis which who write writeisofs fetch \
        xargs yacc yes zdump zmodem pkgin_cd \
-       mktemp worldstone updateboot
+       mktemp worldstone updateboot update_bootcfg
 
 .if ${ARCH} == "i386"
 SUBDIR+=       atnormalize dosread fdisk loadfont \
diff --git a/commands/update_bootcfg/Makefile b/commands/update_bootcfg/Makefile
new file mode 100644 (file)
index 0000000..1583e49
--- /dev/null
@@ -0,0 +1,5 @@
+SCRIPTS= update_bootcfg.sh
+BINDIR= /bin
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/commands/update_bootcfg/update_bootcfg.sh b/commands/update_bootcfg/update_bootcfg.sh
new file mode 100755 (executable)
index 0000000..8c653b6
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/sh
+set -e
+
+ROOT=`printroot -r`
+DEFAULTCFG=/etc/boot.cfg.default
+LOCALCFG=/etc/boot.cfg.local
+TMP=/boot.cfg.temp
+
+filter_missing_entries()
+{
+       while read line
+       do
+               if ! echo "$line" | grep -s -q 'multiboot'
+               then
+                       echo "$line"
+                       continue
+               fi
+
+               # Check if kernel presents
+               kernel=`echo "$line" | sed -n 's/.*multiboot[[:space:]]*\(\/[^[:space:]]*\).*/\1/p'`
+               if [ ! -r "$kernel" ]
+               then
+                       echo "Warning: config contains entry for \"$kernel\" which is missing! Entry skipped." 1>&2
+               else
+                       echo "$line"
+               fi
+       done
+}
+
+if [ ! -b "$ROOT" ]
+then
+       echo root device $ROOT not found
+       exit 1
+fi
+
+rootdevname=`echo $ROOT | sed 's/\/dev\///'`
+
+if [ -r $DEFAULTCFG ]
+then
+       default_cfg=`cat $DEFAULTCFG`
+       # Substitute variables like $rootdevname
+       echo "$default_cfg" | while read line; do eval echo \"$line\" | filter_missing_entries >> $TMP; done
+fi
+
+if [ -e /boot/minix_latest -a -d /boot/minix_latest -o -h /boot/minix_latest ]
+then
+       latest=`basename \`stat -f "%Y" /boot/minix_latest\``
+fi
+
+[ -d /boot/minix ] && for i in `ls /boot/minix/`
+do
+       build_name="`basename $i`"
+       if [ "$build_name" != "$latest" ]
+       then
+               echo "menu=Start MINIX 3 ($build_name):load_mods $i/mod*;multiboot $i/kernel rootdevname=$rootdevname" >> /$TMP
+       fi
+done
+
+[ -r $LOCALCFG ] && cat $LOCALCFG | filter_missing_entries >> $TMP
+
+mv $TMP /boot.cfg
+
+sync
index 99a4ba9ebb3652297cbc7c86f0460f786a3886fb..64dc6b48c9c495b19369776dbac99693cbc6b1d9 100644 (file)
@@ -98,7 +98,7 @@ hdboot: image
        strip -s /boot/minix/.temp/kernel
        [ -d /boot/image ] && ln -f /boot/minix/.temp/kernel /boot/kernel || true
        sh mkboot $@ minix
-       exec sh update_bootcfg.sh
+       sh ../commands/update_bootcfg/update_bootcfg.sh
 
 fdboot:        image
        exec su root mkboot $@
diff --git a/tools/update_bootcfg.sh b/tools/update_bootcfg.sh
deleted file mode 100755 (executable)
index c73863c..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/sh
-set -e
-
-ROOT=`printroot -r`
-DEFAULTCFG=/etc/boot.cfg.default
-LOCALCFG=/etc/boot.cfg.local
-TMP=/boot.cfg.temp
-
-if [ ! -b "$ROOT" ]
-then
-       echo root device $ROOT not found
-       exit 1
-fi
-
-rootdevname=`echo $ROOT | sed 's/\/dev\///'`
-
-if [ -r $DEFAULTCFG ]
-then
-       default_cfg=`cat $DEFAULTCFG`
-       # Substitute variables like $rootdevname
-       echo "$default_cfg" | while read line; do eval echo \"$line\" >> $TMP; done
-fi
-
-latest=`basename \`stat -f "%Y" /boot/minix_latest\``
-
-for i in /boot/minix/*
-do
-       build_name="`basename $i`"
-       if [ "$build_name" != "$latest" ]
-       then
-               echo "menu=Start MINIX 3 ($build_name):load_mods $i/mod*;multiboot $i/kernel rootdevname=$rootdevname" >> /$TMP
-       fi
-done
-
-[ -r $LOCALCFG ] && cat $LOCALCFG >> $TMP
-
-mv $TMP /boot.cfg
-
-sync