Remove building with NOCRYPTO option
[minix3.git] / releasetools / mkboot
blobb2abee8df1971efb27e5cf0ee3fd994c60a83b26
1 #!/bin/sh
3 # mkboot 2.0 - make root device bootable, etc.
4 # Author: Kees J. Bot
6 usage() {
7 echo "Usage: $0 [bootable | hdboot] [DESTDIR]" >&2
8 exit 1
11 rotate_oldest() {
12 base_dir="$1"
13 set -- `ls -t "$base_dir"`
15 case $# in
16 0|1|2|3)
17 # Not much there, do not remove a thing.
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
28 mdec=/usr/mdec # bootstraps
29 # If no DESTDIR specified, then act on / or on the current chroot
30 DESTDIR=
31 # Check arguments.
32 case "$#:$1" in
33 1:bootable | 1:hdboot )
34 # LSC Broken, if $# == 1, then $2,$3 are not set...
35 action=$1
37 2:bootable | 2:hdboot )
38 action=$1 DESTDIR=$2
40 *) usage
41 esac
43 # Get the device table.
44 FSTAB=/etc/fstab
45 touch $FSTAB
46 root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
48 # The real root device may be the RAM disk.
49 realroot=`printroot -r`
51 # If it's an initial fstab, pretend root is real root
52 if [ "$root" = "/dev/ROOT" -o -z "$root" ]
53 then root=$realroot
56 case $action in
57 bootable | hdboot)
58 # We need the root device.
60 if [ $realroot = $root ]
61 then
62 rootdir=
63 else
64 umount $root 2>/dev/null
65 mount $root /mnt || exit
66 rootdir=/mnt
68 esac
70 case $action in
71 hdboot)
72 version=`sh ../sys/conf/osrelease.sh`
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`"
81 revision=`cat revision 2>/dev/null`
83 oldrev=$revision
85 if [ -z "$revision" ]
86 then
87 revision=0
88 rrevision=""
89 gitrev=""
90 else
91 revision=`expr $revision + 1`
92 rrevision=r$revision
95 target="${version}${rrevision}${gitrev}"
97 rotate_oldest "$DESTDIR/boot/minix"
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
107 # Save the revision number.
108 test "$revision" != "$oldrev" && echo $revision >revision
110 test $realroot != $root && umount $root
111 echo "Done."
113 esac
114 sync
115 exit 0