Add chmod o-w /usr
[minix3.git] / tools / release.sh
blob1405c19c9171e1e0f1b7879cc9d4bb29ed50c027
1 #!/bin/sh
3 set -e
5 XBIN=usr/xbin
6 SRC=src
8 PACKAGEDIR=/usr/pkgsrc/packages/`uname -r`/`uname -m`
9 # List of packages included on installation media
10 PACKAGELIST=packages.install
11 secs=`expr 32 '*' 64`
12 export SHELL=/bin/sh
14 PKG_ADD=/usr/pkg/sbin/pkg_add
16 if [ ! -x $PKG_ADD ]
17 then echo Please install pkg_install from pkgsrc.
18 exit 1
21 # Packages we have to pre-install, and url to use
22 PREINSTALLED_PACKAGES="pkgin-0.3.3.4.tgz pkg_install-20101212 bmake-20100808"
23 PACKAGEURL=ftp://ftp.minix3.org/pub/minix/packages/`uname -r`/`uname -m`/All/
25 RELEASERC=$HOME/.releaserc
27 if [ -f $RELEASERC ]
28 then . $RELEASERC
31 set -- $* $RELOPTS
33 # SVN trunk repo
34 TRUNK=https://gforge.cs.vu.nl/svn/minix/trunk
36 make_hdimage()
38 dd if=$TMPDISKUSR of=usrimage bs=$BS count=$USRBLOCKS
40 rootsize=`stat -size rootimage`
41 usrsize=`stat -size usrimage`
43 rootsects=`expr $rootsize / 512`
44 usrsects=`expr $usrsize / 512`
46 # installboot -m needs at least 1KB
47 dd < /dev/zero >tmpimage count=2
48 partition -fm tmpimage 2 81:$rootsects* 0:0 81:$usrsects
49 installboot -m tmpimage /usr/mdec/masterboot
50 dd < tmpimage > subpart count=1
52 primsects=`expr 1 + $rootsects + $usrsects`
53 cyl=`expr '(' $primsects ')' / $secs + 1`
54 padsects=`expr $cyl \* $secs - 1 - $primsects`
56 { dd < /dev/zero count=1
57 cat subpart
58 cat rootimage
59 cat usrimage
60 dd < /dev/zero count=$padsects
61 } > hdimage
62 partition -m hdimage 81:`expr $primsects + $padsects`*
63 installboot -m hdimage /usr/mdec/masterboot
66 retrieve()
68 dir=$1
69 list=`pwd`/$2
70 url=${PACKAGEURL}
72 cd $dir || exit 1
73 echo " * Updating $dir
74 from $url
75 with $list"
76 files=`awk <$list '{ print "'$url'/" $1 ".tgz" }'`
77 fetch -r $files || true
81 cd_root_changes()
83 edparams $TMPDISKROOT 'unset bootopts;
84 unset servers;
85 unset rootdev;
86 unset leader;
87 unset image;
88 disable=inet;
89 bootcd=1;
90 cdproberoot=1;
91 ata_id_timeout=2;
92 bootbig(1, Regular MINIX 3) { unset image; boot }
93 leader() { echo \n--- Welcome to MINIX 3. This is the boot monitor. ---\n\nChoose an option from the menu or press ESC if you need to do anything special.\nOtherwise I will boot with my defaults in 10 seconds.\n\n }; main(){trap 10000 boot; menu; };
94 save'
97 hdemu_root_changes()
99 $RELEASEDIR/usr/bin/installboot -d $TMPDISKROOT \
100 $RELEASEDIR/usr/mdec/bootblock boot/boot
101 echo \
102 'bootcd=2
103 disable=inet
104 bios_wini=yes
105 bios_remap_first=1
106 ramimagedev=c0d7p0s0
107 bootbig(1, Regular MINIX 3) { image=/boot/image_big; boot }
108 main() { trap 10000 boot ; menu; }
109 save' | $RELEASEDIR/usr/bin/edparams $TMPDISKROOT
112 usb_root_changes()
114 $RELEASEDIR/usr/bin/installboot -d $TMPDISKROOT \
115 $RELEASEDIR/usr/mdec/bootblock boot/boot
116 echo \
117 'bios_wini=yes
118 bios_remap_first=1
119 rootdev=c0d7p0s0
120 bootbig(1, Regular MINIX 3) { image=/boot/image_big; boot }
121 leader() { echo \n--- Welcome to MINIX 3. This is the boot monitor. ---\n\nChoose an option from the menu or press ESC if you need to do anything special.\nOtherwise I will boot with my defaults in 10 seconds.\n\n }; main(){trap 10000 boot; menu; };
122 save' | $RELEASEDIR/usr/bin/edparams $TMPDISKROOT
125 fitfs()
127 path="$1"
128 ramdisk="$2"
129 extra_inodes="$3"
130 extra_zones="$4"
131 mbsdefault="$5"
133 # Determine number of inodes
134 inodes=`find $path | egrep -v ^$path/usr | wc -l`
135 inodes="`expr $inodes + $extra_inodes`"
137 # Determine number of data zones
138 zonekbs=`du -Fs $path | cut -d' ' -f1`
139 zonekbsignore=0
140 [ ! -d $path/usr ] || zonekbsignore=`du -Fs $path/usr | cut -d" " -f1`
141 zones="`expr \( $zonekbs - $zonekbsignore \) / \( $BS / 1024 \) + $extra_zones`"
143 # Determine file system size
144 BSBITS="`expr $BS \* 8`"
145 imap_blocks="`expr \( $inodes + $BSBITS - 1 \) / $BSBITS`"
146 inode_blocks="`expr \( $inodes \* 64 + $BS - 1 \) / $BS`"
147 zmap_blocks="`expr \( $zones + $BSBITS - 1 \) / $BSBITS`"
148 blocks="`expr 1 + 1 + $imap_blocks + $zmap_blocks + $inode_blocks + $zones`"
149 kbs="`expr $blocks \* \( $BS / 1024 \)`"
151 # Apply default if higher
152 if [ -n "$mbsdefault" ]
153 then
154 kbsdefault="`expr $mbsdefault \* 1024`"
155 if [ "$kbs" -lt "$kbsdefault" ]
156 then kbs=$kbsdefault
157 else echo "warning: ${mbsdefault}mb is too small, using ${kbs}kb"
161 # Create a filesystem on the target ramdisk
162 ramdisk $kbs $ramdisk
163 mkfs.mfs -B $BS -i $inodes $ramdisk
166 RELEASEDIR=/usr/r-staging
167 RELEASEMNTDIR=/usr/r
168 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
170 IMAGE=../boot/cdbootblock/cdbootblock
171 ROOTIMAGE=rootimage
172 CDFILES=/usr/tmp/cdreleasefiles
173 sh tell_config OS_RELEASE . OS_VERSION >/tmp/rel.$$
174 version_pretty=`sed 's/[" ]//g;/^$/d' </tmp/rel.$$`
175 version=`sed 's/[" ]//g;/^$/d' </tmp/rel.$$ | tr . _`
176 IMG_BASE=minix${version}_ide
177 BS=4096
179 HDEMU=0
180 COPY=0
181 SVNREV=""
182 REVTAG=""
183 PACKAGES=1
184 MINIMAL=0
185 MAKEMAP=0
187 # Do we have git?
188 if git --version >/dev/null
189 then if [ -d ../.git ]
190 then REVTAG="`git describe --always`"
191 echo "git mode; building $REVTAG"
192 GITMODE=1
196 FILENAMEOUT=""
198 while getopts "s:pmMchu?r:f:" c
200 case "$c" in
202 echo "Usage: $0 [-p] [-c] [-h] [-m] [-M] [-r <tag>] [-u] [-f <filename>] [-s <username>]" >&2
203 exit 1
206 echo " * Making HD image"
207 IMG_BASE=minix${version}_bios
208 HDEMU=1
211 echo " * Copying, not SVN"
212 COPY=1
215 PACKAGES=0
218 SVNREV=-r$OPTARG
221 echo " * Making live USB-stick image"
222 IMG_BASE=minix${version}_usb
223 HDEMU=1
224 USB=1
227 FILENAMEOUT="$OPTARG"
229 s) USERNAME="--username=$OPTARG"
231 m) MINIMAL=1
232 PACKAGES=0
234 M) MAKEMAP=1
236 esac
237 done
239 if [ ! "$ZIP" ]
240 then ZIP=bzip2
243 if [ $PACKAGES -ne 0 ]
244 then mkdir -p $PACKAGEDIR/All || true
245 retrieve $PACKAGEDIR/All $PACKAGELIST packages/`uname -p`/`uname -r`
248 if [ "$COPY" -ne 1 ]
249 then
250 echo "Note: this script wants to do svn operations."
253 TMPDISKUSR=/dev/ram0
254 TMPDISKROOT=/dev/ram1
256 if [ ! -b $TMPDISKUSR -o ! $TMPDISKROOT ]
257 then echo "$TMPDISKUSR or $TMPDISKROOT is not a block device.."
258 exit 1
261 if [ $TMPDISKUSR = $TMPDISKROOT ]
262 then
263 echo "Temporary devices can't be equal."
264 exit
267 echo " * Cleanup old files"
268 umount $TMPDISKUSR || true
269 umount $TMPDISKROOT || true
270 umount $RELEASEMNTDIR/usr || true
271 umount $RELEASEMNTDIR || true
273 rm -rf $RELEASEDIR $RELEASEMNTDIR $IMG $ROOTIMAGE $CDFILES image*
274 mkdir -p $CDFILES || exit
275 mkdir -p $RELEASEDIR $RELEASEMNTDIR
276 mkdir -m 755 $RELEASEDIR/usr
277 mkdir -m 1777 $RELEASEDIR/tmp
279 mkdir -p $RELEASEDIR/tmp
280 mkdir -p $RELEASEDIR/usr/tmp
281 mkdir -p $RELEASEDIR/$XBIN
282 mkdir -p $RELEASEDIR/usr/bin
283 mkdir -p $RELEASEDIR/bin
284 mkdir -p $RELEASEPACKAGE
286 echo " * Transfering bootstrap dirs to $RELEASEDIR"
287 cp -p /bin/* /usr/bin/* /sbin/* $RELEASEDIR/$XBIN
288 cp -rp /usr/lib $RELEASEDIR/usr
289 cp -rp /bin/sh /bin/echo $RELEASEDIR/bin
290 cp -rp /usr/bin/make /usr/bin/install /usr/bin/yacc /usr/bin/lex /usr/bin/asmconv $RELEASEDIR/usr/bin
292 CONFIGHEADER=$RELEASEDIR/usr/src/common/include/minix/sys_config.h
294 if [ -d $PACKAGEDIR -a -f $PACKAGELIST -a $PACKAGES -ne 0 ]
295 then
296 index=pkg_summary
297 indexpath=$PACKAGEDIR/.index
299 if [ ! -d $indexpath ]
300 then mkdir $indexpath
302 if [ ! -d $indexpath ]
303 then echo "Couldn't create $indexpath."
304 exit 1
307 echo "" >$PACKAGEDIR/All/$index
309 echo " * Transfering $PACKAGEDIR to $RELEASEPACKAGE"
310 for p in `cat $PACKAGELIST`
311 do if [ -f $PACKAGEDIR/All/$p.tgz ]
312 then
313 # Copy package and create package's index
315 cd $PACKAGEDIR/All
316 cp $p.tgz $RELEASEPACKAGE/
318 f=$p.tgz
319 indexname=$indexpath/$f.$index
320 pkg_info -X $f >$indexname
322 if [ ! -f $indexname ]
323 then echo Missing $indexname.
324 exit 1
327 if [ "`wc -l $indexname`" -lt 3 ]
328 then $indexname is too short.
329 rm $indexname
330 exit 1
333 cat $indexname >>$PACKAGEDIR/All/$index
335 else
336 echo "Can't copy $PACKAGEDIR/$p.tgz. Missing."
338 done
340 bzip2 -f $PACKAGEDIR/All/$index
341 cp $PACKAGEDIR/All/$index.bz2 $RELEASEPACKAGE/
344 # Make sure compilers and libraries are root-owned
345 chown -R root $RELEASEDIR/usr/lib
346 chmod -R u+w $RELEASEDIR/usr/lib
348 if [ "$COPY" -ne 1 -a "$GITMODE" -ne 1 ]
349 then
350 echo " * Doing new svn export"
351 TOOLSREPO="`svn info | grep '^URL: ' | awk '{ print $2 }'`"
352 REPO="`echo $TOOLSREPO | sed 's/.tools$//'`"
353 BRANCHNAME="`echo $REPO | awk -F/ '{ print $NF }'`"
354 REVISION="`svn info $USERNAME $SVNREV $REPO | grep '^Revision: ' | awk '{ print $2 }'`"
355 echo "Doing export of revision $REVISION from $REPO."
356 ( cd $RELEASEDIR/usr && svn -q $USERNAME export -r$REVISION $REPO $SRC )
357 if [ $BRANCHNAME = src ]
358 then REVTAG=r$REVISION
359 else REVTAG=branch-$BRANCHNAME-r$REVISION
362 echo "
364 /* Added by release script */
365 #ifndef _VCS_REVISION
366 #define _VCS_REVISION \"$REVTAG\"
367 #endif" >>$CONFIGHEADER
369 # output image name
370 if [ "$USB" -ne 0 ]; then
371 IMG=${IMG_BASE}_${REVTAG}.img
372 else
373 IMG=${IMG_BASE}_${REVTAG}.iso
376 elif [ "$COPY" -eq 1 ]
377 then
378 ( cd .. && make depend && make clean )
379 srcdir=/usr/$SRC
380 ( cd $srcdir && tar cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
381 REVTAG=copy
382 REVISION=unknown
383 IMG=${IMG_BASE}_copy.iso
384 elif [ "$GITMODE" -eq 1 ]
385 then
386 srcdir=$RELEASEDIR/usr/src
387 git clone file://.. $srcdir
388 ( cd $srcdir && git checkout $REVTAG && rm -r .git )
389 echo "
391 /* Added by release script */
392 #ifndef _VCS_REVISION
393 #define _VCS_REVISION \"$REVTAG\"
394 #endif" >>$CONFIGHEADER
398 echo " * Fixups for owners and modes of dirs and files"
399 chown -R root $RELEASEDIR/usr/$SRC
400 chmod -R u+w $RELEASEDIR/usr/$SRC
401 find $RELEASEDIR/usr/$SRC -type d | xargs chmod 755
402 find $RELEASEDIR/usr/$SRC -type f | xargs chmod 644
403 find $RELEASEDIR/usr/$SRC -name configure | xargs chmod 755
404 find $RELEASEDIR/usr/$SRC/commands -name build | xargs chmod 755
405 # Bug tracking system not for on cd
406 rm -rf $RELEASEDIR/usr/$SRC/doc/bugs
408 # Make sure the CD knows it's a CD, unless it's not
409 if [ "$USB" -eq 0 ]
410 then date >$RELEASEDIR/CD
412 echo " * Bootstrap /usr/share/mk files"
413 # Need /usr/share/mk in the new system to invoke make. Real ownerships
414 # and permissions will be set by its own src/share/mk/Makefile.
415 mkdir -p $RELEASEDIR/usr/share/mk
416 chmod 755 $RELEASEDIR/usr/share/mk
417 cp $RELEASEDIR/usr/src/share/mk/* $RELEASEDIR/usr/share/mk/
418 chown -R root $RELEASEDIR/usr/share/mk
419 cp chrootmake.sh $RELEASEDIR/usr/$SRC/tools/chrootmake.sh
421 echo " * Make hierarchy"
422 chroot $RELEASEDIR "PATH=/$XBIN sh -x /usr/$SRC/tools/chrootmake.sh etcfiles" || exit 1
424 for p in $PREINSTALLED_PACKAGES
425 do echo " * Pre-installing: $p from $PACKAGEURL"
426 $PKG_ADD -P $RELEASEDIR $PACKAGEURL/$p
427 done
429 echo " * Chroot build"
430 chroot $RELEASEDIR "PATH=/$XBIN MAKEMAP=$MAKEMAP sh -x /usr/$SRC/tools/chrootmake.sh" || exit 1
431 # Copy built images for cd booting
432 cp $RELEASEDIR/boot/image_big image
433 echo " * Chroot build done"
434 echo " * Removing bootstrap files"
435 rm -rf $RELEASEDIR/$XBIN
436 # The build process leaves some file in $SRC as bin.
437 chown -R root $RELEASEDIR/usr/src*
438 cp issue.install $RELEASEDIR/etc/issue
440 echo $version_pretty, SVN revision $REVISION, generated `date` >$RELEASEDIR/etc/version
441 rm -rf $RELEASEDIR/tmp/*
442 if [ $MINIMAL -ne 0 ]
443 then
444 if [ "$MAKEMAP" -ne 0 ]
445 then
446 echo " * Copying symbol map to ${IMG}-symbols.txt"
447 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
448 $ZIP -f ${IMG}-symbols.txt
451 echo " * Removing files to create minimal image"
452 rm -rf $RELEASEDIR/boot/image/* $RELEASEDIR/usr/man/man*/* \
453 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
454 mkdir -p $RELEASEDIR/usr/src/tools
455 ln $RELEASEDIR/boot/image_big $RELEASEDIR/boot/image/$version
458 echo " * Counting files"
459 extrakb=`du -s $RELEASEDIR/usr/install | awk '{ print $1 }'`
460 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
461 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
463 echo " * Writing fstab"
464 if [ "$USB" -ne 0 ]
465 then
466 echo \
467 'root=/dev/c0d7p0s0
468 usr=/dev/c0d7p0s2
469 ' > $RELEASEDIR/etc/fstab
470 elif [ "$HDEMU" -ne 0 ]
471 then
472 echo \
473 'root=/dev/c0d7p0s0
474 usr=/dev/c0d7p0s2
475 usr_roflag="-r"' > $RELEASEDIR/etc/fstab
478 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
479 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
480 ROOTBLOCKS=$blocks
481 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
482 mount $TMPDISKROOT $RELEASEMNTDIR || exit
484 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
485 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
486 USRBLOCKS=$blocks
487 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
488 mkdir -m 755 $RELEASEMNTDIR/usr
489 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
491 echo " * Copying files from staging to image"
492 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
493 expr `df $TMPDISKUSR | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
495 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
496 umount $TMPDISKUSR || exit
497 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
498 umount $TMPDISKROOT || exit
499 rm -r $RELEASEMNTDIR
501 echo " * Making image bootable"
502 if [ "$USB" -ne 0 ]
503 then
504 usb_root_changes
505 elif [ "$HDEMU" -ne 0 ]
506 then
507 hdemu_root_changes
508 else
509 cd_root_changes
512 # Clean up: RELEASEDIR no longer needed
513 rm -r $RELEASEDIR
515 (cd ../boot && make)
516 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
517 cp release/cd/* $CDFILES || true
518 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
520 boottype=-n
521 bootimage=$IMAGE
522 if [ "$HDEMU" -ne 0 ]; then
523 make_hdimage
524 boottype='-h'
525 bootimage=hdimage
528 if [ "$USB" -ne 0 ]; then
529 mv $bootimage $IMG
530 else
531 cp ../boot/boot/boot $CDFILES
532 writeisofs -s0x0 -l MINIX -a boot -b $bootimage $boottype $CDFILES $IMG || exit 1
534 if [ "$HDEMU" -eq 0 ]
535 then
536 echo "Appending Minix root and usr filesystem"
537 # Pad ISO out to cylinder boundary
538 isobytes=`stat -size $IMG`
539 isosects=`expr $isobytes / 512`
540 isopad=`expr $secs - '(' $isosects % $secs ')'`
541 dd if=/dev/zero count=$isopad >>$IMG
542 # number of sectors
543 isosects=`expr $isosects + $isopad`
544 ( cat $IMG $ROOTIMAGE ;
545 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
546 mv m $IMG
547 # Make CD partition table
548 installboot -m $IMG /usr/mdec/masterboot
549 # Make sure there is no hole..! Otherwise the ISO format is
550 # unreadable.
551 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
554 echo "${ZIP}ping $IMG"
555 $ZIP -f $IMG
557 if [ "$FILENAMEOUT" ]
558 then echo "$IMG" >$FILENAMEOUT
561 echo " * Freeing up memory used by ramdisks"
562 ramdisk 1 $TMPDISKROOT
563 ramdisk 1 $TMPDISKUSR