ARM divsi3.S: raise(SIGFPE) when called for
[minix.git] / releasetools / mkboot
blob169a8c0f3d06144492917226e61180d346dddfeb
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 if grep -q "Poor man" $FSTAB
47 then . $FSTAB
48 else root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
51 # The real root device may be the RAM disk.
52 realroot=`printroot -r`
54 # If it's an initial fstab, pretend root is real root
55 if [ "$root" = "/dev/ROOT" -o -z "$root" ]
56 then root=$realroot
59 case $action in
60 bootable | hdboot)
61 # We need the root device.
63 if [ $realroot = $root ]
64 then
65 rootdir=
66 else
67 umount $root 2>/dev/null
68 mount $root /mnt || exit
69 rootdir=/mnt
71 esac
73 case $action in
74 hdboot)
75 version=`sh ../sys/conf/osrelease.sh`
77 # Retrieve the git revision; this only succeeds
78 # if git is available, it's a git checkout, *and*
79 # there are no uncommitted changes.
80 if git diff --quiet 2>/dev/null
81 then gitrev="-`git describe --always`"
84 revision=`cat revision 2>/dev/null`
86 oldrev=$revision
88 if [ -z "$revision" ]
89 then
90 revision=0
91 rrevision=""
92 gitrev=""
93 else
94 revision=`expr $revision + 1`
95 rrevision=r$revision
98 target="${version}${rrevision}${gitrev}"
100 rotate_oldest "$DESTDIR/boot/minix"
102 # rotate system processes. We assume latest ones are in
103 # /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
104 [ -d $DESTDIR/boot/minix/.temp ] || exit 1
105 rm -rf $DESTDIR/boot/minix/"$target"/
106 mv $DESTDIR/boot/minix/.temp $DESTDIR/boot/minix/"$target"
107 rm -f $DESTDIR/boot/minix_latest
108 ln -s minix/"$target" $DESTDIR/boot/minix_latest
110 # Save the revision number.
111 test "$revision" != "$oldrev" && echo $revision >revision
113 test $realroot != $root && umount $root
114 echo "Done."
116 esac
117 sync
118 exit 0