iso9660fs: initialize buffer cache
[minix.git] / releasetools / mkboot
blob4ae3299f0d093e5f44909db6ff9ac23a3f6a2453
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]" >&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
32 # Check arguments.
33 case "$#:$1" in
34 1:bootable | 1:hdboot )
35 action=$1 dev=$2 size=$3
37 *) usage
38 esac
40 # Get the device table.
41 FSTAB=/etc/fstab
42 touch $FSTAB
43 if grep -q "Poor man" $FSTAB
44 then . $FSTAB
45 else 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 sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
73 version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
75 # Retrieve the git revision; this only succeeds
76 # if git is available, it's a git checkout, *and*
77 # there are no uncommitted changes.
78 if git diff --quiet 2>/dev/null
79 then gitrev="-`git describe --always`"
82 revision=`cat revision 2>/dev/null`
84 if [ -z "$revision" ]
85 then rrevision=""
86 gitrev=""
87 else rrevision=r$revision
90 oldrev=$revision
92 if [ -z "$revision" ]
93 then
94 revision=0
95 rrevision=""
96 else
97 revision=`expr $revision + 1`
98 rrevision=r$revision
101 target="${version}${rrevision}${gitrev}"
103 rotate_oldest "$rootdir/boot/minix"
105 # rotate system processes. We assume latest ones are in
106 # /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
107 [ -d /boot/minix/.temp ] || exit 1
108 rm -rf /boot/minix/"$target"/
109 mv /boot/minix/.temp /boot/minix/"$target"
110 rm -f /boot/minix_latest
111 ln -s minix/"$target" /boot/minix_latest
113 # Save the revision number.
114 test "$revision" != "$oldrev" && echo $revision >revision
116 test $realroot != $root && umount $root
117 echo "Done."
119 esac
120 sync
121 exit 0