vm: fix sanity checks on arm
[minix.git] / releasetools / release.sh
blob209652c58e531aa04875ccd53c8d25ae452f4d65
1 #!/bin/sh
3 set -e
5 . release.functions
7 version_pretty="`sh ../sys/conf/osrelease.sh`"
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 IMG_BASE=minix${version}_ide
56 BS=4096
58 HDEMU=0
59 COPY=0
60 JAILMODE=0
61 REVTAG=""
62 PACKAGES=1
63 MINIMAL=0
64 MAKEMAP=0
65 EXTRAS_INSTALL=0
66 EXTRAS_PATH=
68 # Do we have git?
69 if git --version >/dev/null
70 then if [ -d ../.git ]
71 then LOCAL_REVTAG="`git describe --always`"
72 GITMODE=1
76 FILENAMEOUT=""
78 while getopts "b:j:ls:pmMchu?f:L:e:" c
80 case "$c" in
81 \?)
82 echo "Usage: $0 [-l] [-p] [-c] [-h] [-m] [-M] [-u] [-f <filename>] [-s <username>] -j<jaildir> [-L <packageurl>] [-e <extras-path>]" >&2
83 exit 1
86 GITBRANCH=$OPTARG
89 echo " * Making HD image"
90 IMG_BASE=minix${version}_bios
91 HDEMU=1
94 echo " * Copying, not using GIT"
95 COPY=1
98 PACKAGES=0
101 RELEASEDIR=$OPTARG
102 JAILMODE=1
105 echo " * Making live USB-stick image"
106 IMG_BASE=minix${version}_usb
107 HDEMU=1
108 USB=1
111 FILENAMEOUT="$OPTARG"
113 s) USERNAME="--username=$OPTARG"
115 m) MINIMAL=1
116 PACKAGES=0
118 M) MAKEMAP=1
120 l) PKG_ADD_URL=file://$PACKAGEDIR/All
122 L) PKG_ADD_URL="$OPTARG"
123 CUSTOM_PACKAGES=1
125 e) EXTRAS_INSTALL=1
126 EXTRAS_PATH="$OPTARG"
128 esac
129 done
131 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
133 if [ $GITMODE -ne 1 -a $COPY -ne 1 ]
134 then echo "Need git to retrieve latest minix! Copying src instead!"
135 COPY=1
138 if [ ! "$ZIP" ]
139 then ZIP=bzip2
142 if [ $PACKAGES -ne 0 ]
143 then mkdir -p $PACKAGEDIR/All || true
144 retrieve $PACKAGEDIR/All $PACKAGELIST packages/`uname -p`/$VERSION_PRETTY
147 TMPDISKUSR=/dev/ram0
148 TMPDISKROOT=/dev/ram1
150 if [ ! -b $TMPDISKUSR -o ! $TMPDISKROOT ]
151 then echo "$TMPDISKUSR or $TMPDISKROOT is not a block device.."
152 exit 1
155 if [ $TMPDISKUSR = $TMPDISKROOT ]
156 then
157 echo "Temporary devices can't be equal."
158 exit
161 if [ $JAILMODE = 0 ]
162 then echo " * Cleanup old files"
163 umount $TMPDISKUSR || true
164 umount $TMPDISKROOT || true
165 umount $RELEASEMNTDIR/usr || true
166 umount $RELEASEMNTDIR || true
169 rm -rf $RELEASEDIR $RELEASEMNTDIR $IMG $ROOTIMAGE $CDFILES image* || true
170 mkdir -p $CDFILES || exit
171 mkdir -p $RELEASEDIR $RELEASEMNTDIR
172 mkdir -p $RELEASEPACKAGE
174 ##########################################################################
175 echo " * Bootstrapping filesystem in $RELEASEDIR"
176 ##########################################################################
177 CONFIGHEADER=$RELEASEDIR/usr/src/include/minix/sys_config.h
179 copy_local_packages
181 if [ "$COPY" -ne 1 ]
182 then
183 echo "Retrieving latest minix repo from $REPO branch $GITBRANCH."
184 srcdir=$RELEASEDIR/usr/src
185 git clone -b $GITBRANCH $REPO $srcdir
186 if [ "$REVTAG" ]
187 then echo "Doing checkout of $REVTAG."
188 (cd $srcdir && git checkout $REVTAG )
189 else REVTAG=`(cd $srcdir && git rev-parse --short HEAD)`
190 echo "Retrieved repository head in $srcdir is $REVTAG."
192 if [ $MINIMAL -ne 0 ]
193 then rm -r $srcdir/.git
195 echo "
196 /* Added by release script */
197 #ifndef _VCS_REVISION
198 #define _VCS_REVISION \"$REVTAG\"
199 #endif" >>$CONFIGHEADER
200 DATE=`date +%Y%m%d`
201 # output image name
202 if [ "$USB" -ne 0 ]; then
203 IMG=${IMG_BASE}_${DATE}_${REVTAG}.img
204 else
205 IMG=${IMG_BASE}_${DATE}_${REVTAG}.iso
207 else
208 echo "First cleaning current sourcedir.."
209 ( cd .. && make cleandir >/dev/null )
210 echo "Copying contents from current src dir."
211 srcdir=/usr/$SRC
212 ( cd $srcdir && tar --exclude .svn -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
213 echo "Copying done."
214 REVTAG=copy
215 REVISION=unknown
216 IMG=${IMG_BASE}_copy.iso
219 # Make sure the CD knows it's a CD, unless it's not
220 if [ "$USB" -eq 0 ]
221 then date >$RELEASEDIR/CD
224 rm -f $RELEASEDIR/usr/$SRC/releasetools/revision
226 for p in $PREINSTALLED_PACKAGES
227 do echo " * Pre-installing: $p from $PKG_ADD_URL"
228 $PKG_ADD -f -P $RELEASEDIR $PKG_ADD_URL/$p
229 done
231 if [ "$CUSTOM_PACKAGES" ]
232 then echo $PKG_ADD_URL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
235 echo " * Resetting timestamps"
236 find $RELEASEDIR | xargs touch
238 ##########################################################################
239 echo " * Build"
240 ##########################################################################
242 cd $RELEASEDIR/usr/src
243 make distribution DESTDIR=$RELEASEDIR CHECKFLIST=no
244 make -C releasetools do-hdboot DESTDIR=$RELEASEDIR MKINSTALLBOOT=yes
245 cp $RELEASEDIR/usr/mdec/boot_monitor $RELEASEDIR
246 cp $RELEASEDIR/boot/minix_latest/* $RELEASEDIR/boot/minix_default/
248 if [ $MAKEMAP -ne 0 ]; then
249 find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
251 make cleandir
253 cd -
255 echo " * build done"
257 ##########################################################################
258 echo " * Removing bootstrap files"
259 ##########################################################################
260 # The build process leaves some file in $SRC as bin.
261 chown -R root $RELEASEDIR/usr/src*
262 cp issue.install $RELEASEDIR/etc/issue
264 echo $version_pretty, SVN revision $REVISION, generated `date` >$RELEASEDIR/etc/version
265 rm -rf $RELEASEDIR/tmp/*
267 if [ $MINIMAL -ne 0 ]
268 then
269 if [ "$MAKEMAP" -ne 0 ]
270 then
271 echo " * Copying symbol map to ${IMG}-symbols.txt"
272 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
273 $ZIP -f ${IMG}-symbols.txt
276 echo " * Removing files to create minimal image"
277 rm -rf $RELEASEDIR/usr/man/man*/* \
278 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
279 mkdir -p $RELEASEDIR/usr/src/releasetools
282 if [ $EXTRAS_INSTALL -ne 0 ] ; then
283 echo " * Copying files from $EXTRAS_PATH"
284 cp -Rv $EXTRAS_PATH/* $RELEASEDIR
287 # If we are making a jail, all is done!
288 if [ $JAILMODE = 1 ]
289 then echo "Created new minix install in $RELEASEDIR."
290 echo "Enter it by typing: "
291 echo "# chroot $RELEASEDIR /bin/sh"
292 exit 0
295 ##########################################################################
296 echo " * Counting files"
297 ##########################################################################
298 extrakb=`du -ks $RELEASEDIR/usr/install | awk '{ print $1 }'`
299 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
300 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
302 fstab_marker="# Poor man's File System Table."
303 echo " * Writing fstab"
304 if [ "$USB" -ne 0 ]
305 then
306 echo \
307 "$fstab_marker
308 root=/dev/c0d7p0s0
309 usr=/dev/c0d7p0s2
310 " > $RELEASEDIR/etc/fstab
311 elif [ "$HDEMU" -ne 0 ]
312 then
313 echo \
314 "$fstab_marker
315 root=/dev/c0d7p0s0
316 usr=/dev/c0d7p0s2
317 usr_roflag=\"-r\"" > $RELEASEDIR/etc/fstab
320 ##########################################################################
321 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
322 ##########################################################################
323 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
324 ROOTBLOCKS=$blocks
325 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
326 mount $TMPDISKROOT $RELEASEMNTDIR || exit
328 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
329 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
330 USRBLOCKS=$blocks
331 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
332 mkdir -m 755 $RELEASEMNTDIR/usr
333 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
335 ##########################################################################
336 echo " * Copying files from staging to image"
337 ##########################################################################
338 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
339 expr `df -k $TMPDISKUSR | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
341 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
342 umount $TMPDISKUSR || exit
344 echo " * Making image bootable"
345 if [ "$USB" -ne 0 ]
346 then
347 usb_root_changes
348 elif [ "$HDEMU" -ne 0 ]
349 then
350 hdemu_root_changes
351 else
352 cd_root_changes
355 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
356 umount $TMPDISKROOT || exit
357 rm -r $RELEASEMNTDIR
359 ##########################################################################
360 echo " * Generating image files"
361 ##########################################################################
362 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
363 cp release/cd/* $CDFILES || true
364 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
366 boottype=-n
367 bootimage=$IMAGE
368 if [ "$HDEMU" -ne 0 ]; then
369 make_hdimage
370 boottype='-h'
371 bootimage=hdimage
374 if [ "$USB" -ne 0 ]; then
375 mv $bootimage $IMG
376 else
377 cp $RELEASEDIR/usr/mdec/boot_monitor $CDFILES/boot
378 cp -rf $RELEASEDIR/boot/minix_latest/* $CDFILES/
379 gzip -d $CDFILES/*gz
380 writeisofs -s0x0 -l MINIX -B $bootimage $boottype $CDFILES $IMG || exit 1
382 if [ "$HDEMU" -eq 0 ]
383 then
384 echo "Appending Minix root and usr filesystem"
385 # Pad ISO out to cylinder boundary
386 isobytes=`stat -f %z $IMG`
387 isosects=`expr $isobytes / 512`
388 isopad=`expr $secs - '(' $isosects % $secs ')'`
389 dd if=/dev/zero count=$isopad >>$IMG
390 # number of sectors
391 isosects=`expr $isosects + $isopad`
392 ( cat $IMG $ROOTIMAGE ;
393 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
394 mv m $IMG
395 # Make CD partition table
396 installboot_nbsd -m $IMG /usr/mdec/mbr
397 # Make sure there is no hole..! Otherwise the ISO format is
398 # unreadable.
399 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
403 # Clean up: RELEASEDIR no longer needed
404 rm -r $RELEASEDIR
406 echo "${ZIP}ping $IMG"
407 $ZIP -f $IMG
409 if [ "$FILENAMEOUT" ]
410 then echo "$IMG" >$FILENAMEOUT
413 ##########################################################################
414 echo " * Freeing up memory used by ramdisks"
415 ##########################################################################
416 ramdisk 1 $TMPDISKROOT
417 ramdisk 1 $TMPDISKUSR