1#!/bin/sh 2# 3# mkboot 2.0 - make root device bootable, etc. 4# Author: Kees J. Bot 5 6usage() { 7 echo "Usage: $0 [bootable | hdboot] [DESTDIR]" >&2 8 exit 1 9} 10 11rotate_oldest() { 12 base_dir="$1" 13 set -- `ls -t "$base_dir"` 14 15 case $# in 16 0|1|2|3) 17 # Not much there, do not remove a thing. 18 ;; 19 *) 20 # Remove the third-newest image in /boot/$hdboot_t, but 21 # only if there's an older one (which is kept). 22 echo "rm $root:$base_dir/$3" 23 rm -rf "$base_dir/$3" 24 esac 25} 26 27 28mdec=/usr/mdec # bootstraps 29# If no DESTDIR specified, then act on / or on the current chroot 30DESTDIR= 31# Check arguments. 32case "$#:$1" in 331:bootable | 1:hdboot ) 34 # LSC Broken, if $# == 1, then $2,$3 are not set... 35 action=$1 36 ;; 372:bootable | 2:hdboot ) 38 action=$1 DESTDIR=$2 39 ;; 40*) usage 41esac 42 43# Get the device table. 44FSTAB=/etc/fstab 45touch $FSTAB 46root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`" 47 48# The real root device may be the RAM disk. 49realroot=`printroot -r` 50 51# If it's an initial fstab, pretend root is real root 52if [ "$root" = "/dev/ROOT" -o -z "$root" ] 53then root=$realroot 54fi 55 56case $action in 57bootable | hdboot) 58 # We need the root device. 59 60 if [ $realroot = $root ] 61 then 62 rootdir= 63 else 64 umount $root 2>/dev/null 65 mount $root /mnt || exit 66 rootdir=/mnt 67 fi 68esac 69 70case $action in 71hdboot) 72 version=`sh ../sys/conf/osrelease.sh` 73 74 # Retrieve the git revision; this only succeeds 75 # if git is available, it's a git checkout, *and* 76 # there are no uncommitted changes. 77 if git diff --quiet 2>/dev/null 78 then gitrev="-`git describe --always`" 79 fi 80 81 revision=`cat revision 2>/dev/null` 82 83 oldrev=$revision 84 85 if [ -z "$revision" ] 86 then 87 revision=0 88 rrevision="" 89 gitrev="" 90 else 91 revision=`expr $revision + 1` 92 rrevision=r$revision 93 fi 94 95 target="${version}${rrevision}${gitrev}" 96 97 rotate_oldest "$DESTDIR/boot/minix" 98 99 # rotate system processes. We assume latest ones are in 100 # /boot/modules/.temp and we maintain /boot/modules/ by ourselves. 101 [ -d $DESTDIR/boot/minix/.temp ] || exit 1 102 rm -rf $DESTDIR/boot/minix/"$target"/ 103 mv $DESTDIR/boot/minix/.temp $DESTDIR/boot/minix/"$target" 104 rm -f $DESTDIR/boot/minix_latest 105 ln -s minix/"$target" $DESTDIR/boot/minix_latest 106 107 # Save the revision number. 108 test "$revision" != "$oldrev" && echo $revision >revision 109 110 test $realroot != $root && umount $root 111 echo "Done." 112 ;; 113esac 114sync 115exit 0 116