2005-04-21 16:53:53 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# mkboot 2.0 - make boot floppy, make root device bootable, etc.
|
|
|
|
# Author: Kees J. Bot
|
|
|
|
|
2012-01-30 13:27:23 +01:00
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [bootable | hdboot [minix or image] | fdboot [device]]" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
rotate_oldest() {
|
|
|
|
base_dir="$1"
|
|
|
|
set -- `ls -t "$base_dir"`
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0|1|2|3)
|
|
|
|
# Not much there, do not remove a thing.
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# Remove the third-newest $hdboot_t in /boot/$hdboot_t, but
|
|
|
|
# only if there's an older one (which is kept).
|
|
|
|
echo "rm $root:$base_dir/$3"
|
|
|
|
rm -rf "$base_dir/$3"
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
|
|
|
|
|
|
|
|
mdec=/usr/mdec # bootstraps
|
|
|
|
|
|
|
|
# Check arguments.
|
|
|
|
case "$#:$1" in
|
2012-01-30 13:27:23 +01:00
|
|
|
1:bootable | 2:hdboot | [12]:fdboot )
|
2009-12-24 00:59:32 +01:00
|
|
|
action=$1 dev=$2 size=$3
|
2005-04-21 16:53:53 +02:00
|
|
|
;;
|
2012-01-30 13:27:23 +01:00
|
|
|
*) usage
|
2005-04-21 16:53:53 +02:00
|
|
|
esac
|
|
|
|
|
2012-01-30 13:27:23 +01:00
|
|
|
if [ "$1" = "hdboot" ]
|
|
|
|
then
|
|
|
|
if [ "$2" != "image" -a "$2" != "minix" ]
|
|
|
|
then usage
|
|
|
|
fi
|
|
|
|
hdboot_t="$2"
|
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
# Get the device table.
|
2011-11-09 16:34:47 +01:00
|
|
|
FSTAB=/etc/fstab
|
|
|
|
touch $FSTAB
|
|
|
|
if grep -q "Poor man" $FSTAB
|
|
|
|
then . $FSTAB
|
|
|
|
else root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
|
|
|
|
fi
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
# The real root device may be the RAM disk.
|
|
|
|
realroot=`printroot -r`
|
|
|
|
|
2005-05-03 10:54:36 +02:00
|
|
|
# If it's an initial fstab, pretend root is real root
|
2011-11-09 16:34:47 +01:00
|
|
|
if [ "$root" = "/dev/ROOT" -o -z "$root" ]
|
2005-05-03 10:54:36 +02:00
|
|
|
then root=$realroot
|
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
case $action in
|
|
|
|
bootable | hdboot)
|
|
|
|
# We need the root device.
|
2005-05-03 10:54:36 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
if [ $realroot = $root ]
|
|
|
|
then
|
|
|
|
rootdir=
|
|
|
|
else
|
|
|
|
umount $root 2>/dev/null
|
|
|
|
mount $root /mnt || exit
|
|
|
|
rootdir=/mnt
|
|
|
|
fi
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $action in
|
|
|
|
hdboot)
|
|
|
|
# Install a new image on the root device.
|
2012-01-30 13:27:23 +01:00
|
|
|
if [ -e $rootdir/boot/$hdboot_t -a ! -d $rootdir/boot/$hdboot_t ]
|
2005-04-21 16:53:53 +02:00
|
|
|
then
|
2012-01-30 13:27:23 +01:00
|
|
|
# /boot/$hdboot_t is not yet a directory! Fix it.
|
2005-04-21 16:53:53 +02:00
|
|
|
su root -c \
|
2012-01-30 13:27:23 +01:00
|
|
|
"exec mv $rootdir/boot/$hdboot_t /M"
|
|
|
|
install -d $rootdir/boot/$hdboot_t
|
2005-04-21 16:53:53 +02:00
|
|
|
su root -c \
|
2012-01-30 13:27:23 +01:00
|
|
|
"exec mv $rootdir/M $rootdir/boot/$hdboot_t/`uname -r`"
|
2005-04-21 16:53:53 +02:00
|
|
|
fi
|
|
|
|
|
2005-05-03 17:37:34 +02:00
|
|
|
sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
|
2005-04-21 16:53:53 +02:00
|
|
|
version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
|
|
|
|
|
2010-11-25 16:25:17 +01:00
|
|
|
# Retrieve the git revision; this only succeeds
|
|
|
|
# if git is available, it's a git checkout, *and*
|
|
|
|
# there are no uncommitted changes.
|
|
|
|
if git diff --quiet 2>/dev/null
|
|
|
|
then gitrev="-`git describe --always`"
|
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
revision=`cat revision 2>/dev/null`
|
2006-01-18 14:26:50 +01:00
|
|
|
|
|
|
|
if [ -z "$revision" ]
|
|
|
|
then rrevision=""
|
2010-11-25 16:25:17 +01:00
|
|
|
gitrev=""
|
2006-01-18 14:26:50 +01:00
|
|
|
else rrevision=r$revision
|
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
oldrev=$revision
|
2006-01-18 14:26:50 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
if [ -z "$revision" ]
|
|
|
|
then
|
|
|
|
revision=0
|
2006-01-18 13:37:45 +01:00
|
|
|
rrevision=""
|
2010-11-25 16:25:17 +01:00
|
|
|
else
|
2005-04-21 16:53:53 +02:00
|
|
|
revision=`expr $revision + 1`
|
2006-01-18 14:26:50 +01:00
|
|
|
rrevision=r$revision
|
2005-04-21 16:53:53 +02:00
|
|
|
fi
|
2010-11-25 16:25:17 +01:00
|
|
|
|
|
|
|
target="${version}${rrevision}${gitrev}"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-01-30 13:27:23 +01:00
|
|
|
rotate_oldest "$rootdir/boot/$hdboot_t"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-01-30 13:27:23 +01:00
|
|
|
# rotate system processes. We assume latest ones are in
|
|
|
|
# /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
|
|
|
|
if [ "$hdboot_t" = "minix" ]
|
|
|
|
then
|
|
|
|
[ -d /boot/minix/.temp ] || exit 1
|
|
|
|
mv /boot/minix/.temp /boot/minix/"$target"
|
|
|
|
rm -f /boot/minix_latest
|
2012-02-15 01:19:12 +01:00
|
|
|
ln -s minix/"$target" /boot/minix_latest
|
2012-01-30 13:27:23 +01:00
|
|
|
else
|
|
|
|
# Install the new image.
|
|
|
|
echo "install $hdboot_t $root:/boot/$hdboot_t/$target"
|
|
|
|
install -o root -m 600 $hdboot_t $rootdir/boot/$hdboot_t/$target || exit 1
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-01-30 13:27:23 +01:00
|
|
|
# Tell bootloader which image is newest
|
|
|
|
ln -f $rootdir/boot/$hdboot_t/$target $rootdir/boot/${hdboot_t}_latest
|
2010-07-23 16:24:34 +02:00
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
# Save the revision number.
|
|
|
|
test "$revision" != "$oldrev" && echo $revision >revision
|
|
|
|
|
|
|
|
test $realroot != $root && umount $root
|
|
|
|
echo "Done."
|
|
|
|
;;
|
|
|
|
esac
|
2005-05-24 14:03:42 +02:00
|
|
|
sync
|
2005-04-21 16:53:53 +02:00
|
|
|
exit 0
|