2012-02-16 14:38:38 +01:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
|
|
|
ROOT=`printroot -r`
|
|
|
|
DEFAULTCFG=/etc/boot.cfg.default
|
|
|
|
LOCALCFG=/etc/boot.cfg.local
|
|
|
|
TMP=/boot.cfg.temp
|
2012-04-18 16:30:06 +02:00
|
|
|
DIRSBASE=/boot/minix
|
2012-10-16 00:40:35 +02:00
|
|
|
INHERIT="ahci acpi no_apic"
|
2012-02-16 14:38:38 +01:00
|
|
|
|
2012-10-16 00:40:35 +02:00
|
|
|
filter_entries()
|
2012-02-16 14:38:38 +01:00
|
|
|
{
|
2012-10-16 00:40:35 +02:00
|
|
|
# This routine performs three tasks:
|
|
|
|
# - substitute variables in the configuration lines;
|
|
|
|
# - remove multiboot entries that refer to nonexistent kernels;
|
|
|
|
# - adjust the default option for line removal and different files.
|
|
|
|
# The last part is handled by the awk part of the routine.
|
|
|
|
|
2012-02-16 14:38:38 +01:00
|
|
|
while read line
|
|
|
|
do
|
2012-10-16 00:40:35 +02:00
|
|
|
# Substitute variables like $rootdevname and $args
|
|
|
|
line=$(eval echo \"$line\")
|
|
|
|
|
|
|
|
if ! echo "$line" | grep -sq '^menu=.*multiboot'
|
2012-02-16 14:38:38 +01:00
|
|
|
then
|
|
|
|
echo "$line"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2012-10-16 00:40:35 +02:00
|
|
|
# Check if the referenced kernel is present
|
2012-02-16 14:38:38 +01:00
|
|
|
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
|
2012-10-16 00:40:35 +02:00
|
|
|
echo "menu=SKIP"
|
2012-02-16 14:38:38 +01:00
|
|
|
else
|
|
|
|
echo "$line"
|
|
|
|
fi
|
2012-10-16 00:40:35 +02:00
|
|
|
done | awk '
|
|
|
|
BEGIN {
|
|
|
|
count=1
|
|
|
|
base=0
|
|
|
|
default=0
|
|
|
|
}
|
|
|
|
/^menu=SKIP$/ {
|
|
|
|
# A menu entry discarded by the kernel check above
|
|
|
|
skip[count++]=1
|
|
|
|
next
|
|
|
|
}
|
|
|
|
/^menu=/ {
|
|
|
|
# A valid menu entry
|
|
|
|
skip[count++]=0
|
|
|
|
print
|
|
|
|
next
|
|
|
|
}
|
|
|
|
/^BASE=/ {
|
|
|
|
# The menu count base as passed in by count_entries()
|
|
|
|
sub(/^.*=/,"",$1)
|
|
|
|
base=$1+0
|
|
|
|
next
|
|
|
|
}
|
|
|
|
/^default=/ {
|
|
|
|
# The default option
|
|
|
|
# Correct for the menu count base and store for later
|
|
|
|
sub(/^.*=/,"",$1)
|
|
|
|
default=$1+base
|
|
|
|
next
|
|
|
|
}
|
|
|
|
{
|
|
|
|
# Any other line
|
|
|
|
print
|
|
|
|
}
|
|
|
|
END {
|
|
|
|
# If a default was given, correct for removed lines
|
|
|
|
# (do not bother to warn if the default itself is gone)
|
|
|
|
if (default) {
|
|
|
|
for (i = default; i > 0; i--)
|
|
|
|
if (skip[i]) default--;
|
|
|
|
print "default=" default
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
count_entries()
|
|
|
|
{
|
|
|
|
echo -n "BASE="; grep -cs '^menu=' "$1"
|
2012-02-16 14:38:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! -b "$ROOT" ]
|
|
|
|
then
|
|
|
|
echo root device $ROOT not found
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rootdevname=`echo $ROOT | sed 's/\/dev\///'`
|
|
|
|
|
2012-10-16 00:40:35 +02:00
|
|
|
# Construct a list of inherited arguments for boot options to use. Note that
|
|
|
|
# rootdevname must not be passed on this way, as it is changed during setup.
|
|
|
|
args=""
|
|
|
|
for k in $INHERIT; do
|
|
|
|
if sysenv | grep -sq "^$k="; then
|
|
|
|
kv=$(sysenv | grep "^$k=")
|
|
|
|
args="$args $kv"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2012-02-16 14:38:38 +01:00
|
|
|
if [ -r $DEFAULTCFG ]
|
|
|
|
then
|
2012-10-16 00:40:35 +02:00
|
|
|
filter_entries < $DEFAULTCFG >> $TMP
|
2012-02-16 14:38:38 +01:00
|
|
|
fi
|
|
|
|
|
2012-10-16 00:40:35 +02:00
|
|
|
if [ -d /boot/minix_latest -o -h /boot/minix_latest ]
|
2012-02-16 14:38:38 +01:00
|
|
|
then
|
|
|
|
latest=`basename \`stat -f "%Y" /boot/minix_latest\``
|
|
|
|
fi
|
|
|
|
|
2012-04-18 16:30:06 +02:00
|
|
|
[ -d $DIRSBASE ] && for i in `ls $DIRSBASE/`
|
2012-02-16 14:38:38 +01:00
|
|
|
do
|
|
|
|
build_name="`basename $i`"
|
|
|
|
if [ "$build_name" != "$latest" ]
|
|
|
|
then
|
2012-10-16 00:40:35 +02:00
|
|
|
echo "menu=Start MINIX 3 ($build_name):load_mods $DIRSBASE/$i/mod*;multiboot $DIRSBASE/$i/kernel rootdevname=$rootdevname $args" >> $TMP
|
2012-02-16 14:38:38 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2012-10-16 00:40:35 +02:00
|
|
|
if [ -r $LOCALCFG ]
|
|
|
|
then
|
|
|
|
# If the local config supplies a "default" option, we assume that this
|
|
|
|
# refers to one of the options in the local config itself. Therefore,
|
|
|
|
# we increase this default by the number of options already present in
|
|
|
|
# the output so far. To this end, count_entries() inserts a special
|
|
|
|
# token that is recognized and filtered out by filter_entries().
|
|
|
|
(count_entries $TMP; cat $LOCALCFG) | filter_entries >> $TMP
|
|
|
|
fi
|
2012-02-16 14:38:38 +01:00
|
|
|
|
|
|
|
mv $TMP /boot.cfg
|
|
|
|
|
|
|
|
sync
|