minix/releasetools/mkboot

119 lines
2.3 KiB
Text
Raw Normal View History

2005-04-21 16:53:53 +02:00
#!/bin/sh
#
# mkboot 2.0 - make root device bootable, etc.
2005-04-21 16:53:53 +02:00
# Author: Kees J. Bot
usage() {
echo "Usage: $0 [bootable | hdboot] [DESTDIR]" >&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.
;;
*)
2012-05-01 13:55:49 +02:00
# 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
}
2005-04-21 16:53:53 +02:00
mdec=/usr/mdec # bootstraps
# If no DESTDIR specified, then act on / or on the current chroot
DESTDIR=
2005-04-21 16:53:53 +02:00
# Check arguments.
case "$#:$1" in
1:bootable | 1:hdboot )
# LSC Broken, if $# == 1, then $2,$3 are not set...
action=$1
;;
2:bootable | 2:hdboot )
action=$1 DESTDIR=$2
2005-04-21 16:53:53 +02:00
;;
*) usage
2005-04-21 16:53:53 +02:00
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
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
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)
version=`sh ../sys/conf/osrelease.sh`
2005-04-21 16:53:53 +02: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
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
rrevision=""
gitrev=""
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
target="${version}${rrevision}${gitrev}"
2005-04-21 16:53:53 +02:00
rotate_oldest "$DESTDIR/boot/minix"
2005-04-21 16:53:53 +02:00
# rotate system processes. We assume latest ones are in
# /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
[ -d $DESTDIR/boot/minix/.temp ] || exit 1
rm -rf $DESTDIR/boot/minix/"$target"/
mv $DESTDIR/boot/minix/.temp $DESTDIR/boot/minix/"$target"
rm -f $DESTDIR/boot/minix_latest
ln -s minix/"$target" $DESTDIR/boot/minix_latest
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
sync
2005-04-21 16:53:53 +02:00
exit 0