sprofalyze fixes
[minix.git] / releasetools / mkboot
blobec72b3787586a529c99c3288c6622c22e78509d5
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 trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
30 mdec=/usr/mdec # bootstraps
31 # If no DESTDIR specified, then act on / or on the current chroot
32 DESTDIR=
33 # Check arguments.
34 case "$#:$1" in
35 1:bootable | 1:hdboot )
36 # LSC Broken, if $# == 1, then $2,$3 are not set...
37 action=$1
39 2:bootable | 2:hdboot )
40 action=$1 DESTDIR=$2
42 *) usage
43 esac
45 # Get the device table.
46 FSTAB=/etc/fstab
47 touch $FSTAB
48 if grep -q "Poor man" $FSTAB
49 then . $FSTAB
50 else root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
53 # The real root device may be the RAM disk.
54 realroot=`printroot -r`
56 # If it's an initial fstab, pretend root is real root
57 if [ "$root" = "/dev/ROOT" -o -z "$root" ]
58 then root=$realroot
61 case $action in
62 bootable | hdboot)
63 # We need the root device.
65 if [ $realroot = $root ]
66 then
67 rootdir=
68 else
69 umount $root 2>/dev/null
70 mount $root /mnt || exit
71 rootdir=/mnt
73 esac
75 case $action in
76 hdboot)
77 sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
78 version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
80 # Retrieve the git revision; this only succeeds
81 # if git is available, it's a git checkout, *and*
82 # there are no uncommitted changes.
83 if git diff --quiet 2>/dev/null
84 then gitrev="-`git describe --always`"
87 revision=`cat revision 2>/dev/null`
89 if [ -z "$revision" ]
90 then rrevision=""
91 gitrev=""
92 else rrevision=r$revision
95 oldrev=$revision
97 if [ -z "$revision" ]
98 then
99 revision=0
100 rrevision=""
101 else
102 revision=`expr $revision + 1`
103 rrevision=r$revision
106 target="${version}${rrevision}${gitrev}"
108 rotate_oldest "$DESTDIR/boot/minix"
110 # rotate system processes. We assume latest ones are in
111 # /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
112 [ -d $DESTDIR/boot/minix/.temp ] || exit 1
113 rm -rf $DESTDIR/boot/minix/"$target"/
114 mv $DESTDIR/boot/minix/.temp $DESTDIR/boot/minix/"$target"
115 rm -f $DESTDIR/boot/minix_latest
116 ln -s minix/"$target" $DESTDIR/boot/minix_latest
118 # Save the revision number.
119 test "$revision" != "$oldrev" && echo $revision >revision
121 test $realroot != $root && umount $root
122 echo "Done."
124 esac
125 sync
126 exit 0