vm: fix region reporting bug
[minix.git] / releasetools / release.sh
blob18acc0486e758064265318e79e7d76c53f2ac19f
1 #!/bin/sh
3 set -e
5 . release.functions
7 version_pretty="`sh tell_config OS_RELEASE . OS_VERSION | tr -dc 0-9.`"
8 version="`echo $version_pretty | tr . _`"
9 PACKAGEDIR=/usr/pkgsrc/packages/$version_pretty/`uname -m`
11 SRC=src
12 REPO=git://git.minix3.org/minix
13 GITBRANCH=master
15 # List of packages included on installation media
16 PACKAGELIST=packages.install
17 secs=`expr 32 '*' 64`
18 export SHELL=/bin/sh
20 PKG_ADD=/usr/pkg/sbin/pkg_add
21 PKG_INFO=/usr/pkg/sbin/pkg_info
23 if [ ! -x $PKG_ADD ]
24 then echo Please install pkg_install from pkgsrc.
25 exit 1
28 # Packages we have to pre-install, and url to use
29 PACKAGEURL=ftp://ftp.minix3.org/pub/minix/packages/$version_pretty/`uname -m`/All/
30 PREINSTALLED_PACKAGES="
31 pkgin
32 pkg_install
33 bmake
34 binutils
35 clang
37 # pkg_tarup
39 PKG_ADD_URL=$PACKAGEURL
41 RELEASERC=$HOME/.releaserc
43 if [ -f $RELEASERC ]
44 then . $RELEASERC
47 set -- $* $RELOPTS
49 export RELEASEDIR=/usr/r-staging
50 RELEASEMNTDIR=/usr/r
52 IMAGE=/usr/mdec/bootxx_cd9660
53 ROOTIMAGE=rootimage
54 CDFILES=/usr/tmp/cdreleasefiles
55 sh tell_config OS_RELEASE . OS_VERSION >/tmp/rel.$$
56 IMG_BASE=minix${version}_ide
57 BS=4096
59 HDEMU=0
60 COPY=0
61 JAILMODE=0
62 REVTAG=""
63 PACKAGES=1
64 MINIMAL=0
65 MAKEMAP=0
66 EXTRAS_INSTALL=0
67 EXTRAS_PATH=
69 # Do we have git?
70 if git --version >/dev/null
71 then if [ -d ../.git ]
72 then LOCAL_REVTAG="`git describe --always`"
73 GITMODE=1
77 FILENAMEOUT=""
79 while getopts "b:j:ls:pmMchu?f:L:e:" c
81 case "$c" in
82 \?)
83 echo "Usage: $0 [-l] [-p] [-c] [-h] [-m] [-M] [-u] [-f <filename>] [-s <username>] -j<jaildir> [-L <packageurl>] [-e <extras-path>]" >&2
84 exit 1
87 GITBRANCH=$OPTARG
90 echo " * Making HD image"
91 IMG_BASE=minix${version}_bios
92 HDEMU=1
95 echo " * Copying, not using GIT"
96 COPY=1
99 PACKAGES=0
102 RELEASEDIR=$OPTARG
103 JAILMODE=1
106 echo " * Making live USB-stick image"
107 IMG_BASE=minix${version}_usb
108 HDEMU=1
109 USB=1
112 FILENAMEOUT="$OPTARG"
114 s) USERNAME="--username=$OPTARG"
116 m) MINIMAL=1
117 PACKAGES=0
119 M) MAKEMAP=1
121 l) PKG_ADD_URL=file://$PACKAGEDIR/All
123 L) PKG_ADD_URL="$OPTARG"
124 CUSTOM_PACKAGES=1
126 e) EXTRAS_INSTALL=1
127 EXTRAS_PATH="$OPTARG"
129 esac
130 done
132 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
134 if [ $GITMODE -ne 1 -a $COPY -ne 1 ]
135 then echo "Need git to retrieve latest minix! Copying src instead!"
136 COPY=1
139 if [ ! "$ZIP" ]
140 then ZIP=bzip2
143 if [ $PACKAGES -ne 0 ]
144 then mkdir -p $PACKAGEDIR/All || true
145 retrieve $PACKAGEDIR/All $PACKAGELIST packages/`uname -p`/$VERSION_PRETTY
148 TMPDISKUSR=/dev/ram0
149 TMPDISKROOT=/dev/ram1
151 if [ ! -b $TMPDISKUSR -o ! $TMPDISKROOT ]
152 then echo "$TMPDISKUSR or $TMPDISKROOT is not a block device.."
153 exit 1
156 if [ $TMPDISKUSR = $TMPDISKROOT ]
157 then
158 echo "Temporary devices can't be equal."
159 exit
162 if [ $JAILMODE = 0 ]
163 then echo " * Cleanup old files"
164 umount $TMPDISKUSR || true
165 umount $TMPDISKROOT || true
166 umount $RELEASEMNTDIR/usr || true
167 umount $RELEASEMNTDIR || true
170 rm -rf $RELEASEDIR $RELEASEMNTDIR $IMG $ROOTIMAGE $CDFILES image* || true
171 mkdir -p $CDFILES || exit
172 mkdir -p $RELEASEDIR $RELEASEMNTDIR
173 mkdir -p $RELEASEPACKAGE
175 ##########################################################################
176 echo " * Bootstrapping filesystem in $RELEASEDIR"
177 ##########################################################################
178 CONFIGHEADER=$RELEASEDIR/usr/src/include/minix/sys_config.h
180 copy_local_packages
182 if [ "$COPY" -ne 1 ]
183 then
184 echo "Retrieving latest minix repo from $REPO branch $GITBRANCH."
185 srcdir=$RELEASEDIR/usr/src
186 git clone -b $GITBRANCH $REPO $srcdir
187 if [ "$REVTAG" ]
188 then echo "Doing checkout of $REVTAG."
189 (cd $srcdir && git checkout $REVTAG )
190 else REVTAG=`(cd $srcdir && git rev-parse --short HEAD)`
191 echo "Retrieved repository head in $srcdir is $REVTAG."
193 if [ $MINIMAL -ne 0 ]
194 then rm -r $srcdir/.git
196 echo "
197 /* Added by release script */
198 #ifndef _VCS_REVISION
199 #define _VCS_REVISION \"$REVTAG\"
200 #endif" >>$CONFIGHEADER
201 DATE=`date +%Y%m%d`
202 # output image name
203 if [ "$USB" -ne 0 ]; then
204 IMG=${IMG_BASE}_${DATE}_${REVTAG}.img
205 else
206 IMG=${IMG_BASE}_${DATE}_${REVTAG}.iso
208 else
209 echo "First cleaning current sourcedir.."
210 ( cd .. && make cleandir >/dev/null )
211 echo "Copying contents from current src dir."
212 srcdir=/usr/$SRC
213 ( cd $srcdir && tar --exclude .svn -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
214 echo "Copying done."
215 REVTAG=copy
216 REVISION=unknown
217 IMG=${IMG_BASE}_copy.iso
220 # Make sure the CD knows it's a CD, unless it's not
221 if [ "$USB" -eq 0 ]
222 then date >$RELEASEDIR/CD
225 rm -f $RELEASEDIR/usr/$SRC/releasetools/revision
227 for p in $PREINSTALLED_PACKAGES
228 do echo " * Pre-installing: $p from $PKG_ADD_URL"
229 $PKG_ADD -f -P $RELEASEDIR $PKG_ADD_URL/$p
230 done
232 if [ "$CUSTOM_PACKAGES" ]
233 then echo $PKG_ADD_URL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
236 echo " * Resetting timestamps"
237 find $RELEASEDIR | xargs touch
239 ##########################################################################
240 echo " * Build"
241 ##########################################################################
243 cd $RELEASEDIR/usr/src
244 make distribution DESTDIR=$RELEASEDIR CHECKFLIST=no
245 make -C releasetools do-hdboot DESTDIR=$RELEASEDIR MKINSTALLBOOT=yes
246 cp $RELEASEDIR/usr/mdec/boot_monitor $RELEASEDIR
247 cp $RELEASEDIR/boot/minix_latest/* $RELEASEDIR/boot/minix_default/
249 if [ $MAKEMAP -ne 0 ]; then
250 find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
252 make cleandir
254 cd -
256 echo " * build done"
258 ##########################################################################
259 echo " * Removing bootstrap files"
260 ##########################################################################
261 # The build process leaves some file in $SRC as bin.
262 chown -R root $RELEASEDIR/usr/src*
263 cp issue.install $RELEASEDIR/etc/issue
265 echo $version_pretty, SVN revision $REVISION, generated `date` >$RELEASEDIR/etc/version
266 rm -rf $RELEASEDIR/tmp/*
268 if [ $MINIMAL -ne 0 ]
269 then
270 if [ "$MAKEMAP" -ne 0 ]
271 then
272 echo " * Copying symbol map to ${IMG}-symbols.txt"
273 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
274 $ZIP -f ${IMG}-symbols.txt
277 echo " * Removing files to create minimal image"
278 rm -rf $RELEASEDIR/usr/man/man*/* \
279 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
280 mkdir -p $RELEASEDIR/usr/src/releasetools
283 if [ $EXTRAS_INSTALL -ne 0 ] ; then
284 echo " * Copying files from $EXTRAS_PATH"
285 cp -Rv $EXTRAS_PATH/* $RELEASEDIR
288 # If we are making a jail, all is done!
289 if [ $JAILMODE = 1 ]
290 then echo "Created new minix install in $RELEASEDIR."
291 echo "Enter it by typing: "
292 echo "# chroot $RELEASEDIR /bin/sh"
293 exit 0
296 ##########################################################################
297 echo " * Counting files"
298 ##########################################################################
299 extrakb=`du -ks $RELEASEDIR/usr/install | awk '{ print $1 }'`
300 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
301 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
303 fstab_marker="# Poor man's File System Table."
304 echo " * Writing fstab"
305 if [ "$USB" -ne 0 ]
306 then
307 echo \
308 "$fstab_marker
309 root=/dev/c0d7p0s0
310 usr=/dev/c0d7p0s2
311 " > $RELEASEDIR/etc/fstab
312 elif [ "$HDEMU" -ne 0 ]
313 then
314 echo \
315 "$fstab_marker
316 root=/dev/c0d7p0s0
317 usr=/dev/c0d7p0s2
318 usr_roflag=\"-r\"" > $RELEASEDIR/etc/fstab
321 ##########################################################################
322 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
323 ##########################################################################
324 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
325 ROOTBLOCKS=$blocks
326 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
327 mount $TMPDISKROOT $RELEASEMNTDIR || exit
329 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
330 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
331 USRBLOCKS=$blocks
332 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
333 mkdir -m 755 $RELEASEMNTDIR/usr
334 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
336 ##########################################################################
337 echo " * Copying files from staging to image"
338 ##########################################################################
339 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
340 expr `df -k $TMPDISKUSR | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
342 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
343 umount $TMPDISKUSR || exit
345 echo " * Making image bootable"
346 if [ "$USB" -ne 0 ]
347 then
348 usb_root_changes
349 elif [ "$HDEMU" -ne 0 ]
350 then
351 hdemu_root_changes
352 else
353 cd_root_changes
356 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
357 umount $TMPDISKROOT || exit
358 rm -r $RELEASEMNTDIR
360 ##########################################################################
361 echo " * Generating image files"
362 ##########################################################################
363 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
364 cp release/cd/* $CDFILES || true
365 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
367 boottype=-n
368 bootimage=$IMAGE
369 if [ "$HDEMU" -ne 0 ]; then
370 make_hdimage
371 boottype='-h'
372 bootimage=hdimage
375 if [ "$USB" -ne 0 ]; then
376 mv $bootimage $IMG
377 else
378 cp $RELEASEDIR/usr/mdec/boot_monitor $CDFILES/boot
379 cp -rf $RELEASEDIR/boot/minix_latest/* $CDFILES/
380 gzip -d $CDFILES/*gz
381 writeisofs -s0x0 -l MINIX -B $bootimage $boottype $CDFILES $IMG || exit 1
383 if [ "$HDEMU" -eq 0 ]
384 then
385 echo "Appending Minix root and usr filesystem"
386 # Pad ISO out to cylinder boundary
387 isobytes=`stat -f %z $IMG`
388 isosects=`expr $isobytes / 512`
389 isopad=`expr $secs - '(' $isosects % $secs ')'`
390 dd if=/dev/zero count=$isopad >>$IMG
391 # number of sectors
392 isosects=`expr $isosects + $isopad`
393 ( cat $IMG $ROOTIMAGE ;
394 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
395 mv m $IMG
396 # Make CD partition table
397 installboot_nbsd -m $IMG /usr/mdec/mbr
398 # Make sure there is no hole..! Otherwise the ISO format is
399 # unreadable.
400 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
404 # Clean up: RELEASEDIR no longer needed
405 rm -r $RELEASEDIR
407 echo "${ZIP}ping $IMG"
408 $ZIP -f $IMG
410 if [ "$FILENAMEOUT" ]
411 then echo "$IMG" >$FILENAMEOUT
414 ##########################################################################
415 echo " * Freeing up memory used by ramdisks"
416 ##########################################################################
417 ramdisk 1 $TMPDISKROOT
418 ramdisk 1 $TMPDISKUSR