minix/releasetools/mkboot
Thomas Veerman 7f99f3a293 Rename tools to releasetools
This is in preparation of NetBSD's tools directory to build tools
for cross compilation.
2012-06-18 10:53:37 +00:00

121 lines
2.3 KiB
Bash
Executable file

#!/bin/sh
#
# mkboot 2.0 - make boot floppy, make root device bootable, etc.
# Author: Kees J. Bot
usage() {
echo "Usage: $0 [bootable | hdboot | 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 image 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
}
trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
mdec=/usr/mdec # bootstraps
# Check arguments.
case "$#:$1" in
1:bootable | 1:hdboot | [12]:fdboot )
action=$1 dev=$2 size=$3
;;
*) usage
esac
# Get the device table.
FSTAB=/etc/fstab
touch $FSTAB
if grep -q "Poor man" $FSTAB
then . $FSTAB
else root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
fi
# The real root device may be the RAM disk.
realroot=`printroot -r`
# If it's an initial fstab, pretend root is real root
if [ "$root" = "/dev/ROOT" -o -z "$root" ]
then root=$realroot
fi
case $action in
bootable | hdboot)
# We need the root device.
if [ $realroot = $root ]
then
rootdir=
else
umount $root 2>/dev/null
mount $root /mnt || exit
rootdir=/mnt
fi
esac
case $action in
hdboot)
sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
# 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
revision=`cat revision 2>/dev/null`
if [ -z "$revision" ]
then rrevision=""
gitrev=""
else rrevision=r$revision
fi
oldrev=$revision
if [ -z "$revision" ]
then
revision=0
rrevision=""
else
revision=`expr $revision + 1`
rrevision=r$revision
fi
target="${version}${rrevision}${gitrev}"
rotate_oldest "$rootdir/boot/minix"
# rotate system processes. We assume latest ones are in
# /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
[ -d /boot/minix/.temp ] || exit 1
rm -rf /boot/minix/"$target"/
mv /boot/minix/.temp /boot/minix/"$target"
rm -f /boot/minix_latest
ln -s minix/"$target" /boot/minix_latest
# Save the revision number.
test "$revision" != "$oldrev" && echo $revision >revision
test $realroot != $root && umount $root
echo "Done."
;;
esac
sync
exit 0