New P_BLOCKEDON for kernel - a macro that encodes the "who is this
[minix.git] / tools / release.sh
blob639a8475df8f9be6eb908f695287172374f296ed
1 #!/bin/sh
3 set -e
5 PATH=$PATH:/usr/local/bin
7 XBIN=usr/xbin
8 SRC=src
10 # size of /tmp during build
11 TMPKB=32000
13 PACKAGEDIR=/usr/bigports/Packages
14 PACKAGESOURCEDIR=/usr/bigports/Sources
15 # List of packages included on installation media
16 PACKAGELIST=packages.install
17 # List of package source included on installation media
18 PACKAGESOURCELIST=package_sources.install
19 secs=`expr 32 '*' 64`
20 export SHELL=/bin/sh
22 # SVN trunk repo
23 TRUNK=https://gforge.cs.vu.nl/svn/minix/trunk
25 make_hdimage()
27 dd if=$TMPDISK1 of=usrimage bs=$BS count=$USRBLOCKS
29 rootsize=`stat -size rootimage`
30 usrsize=`stat -size usrimage`
32 rootsects=`expr $rootsize / 512`
33 usrsects=`expr $usrsize / 512`
35 # installboot -m needs at least 1KB
36 dd < /dev/zero >tmpimage count=2
37 partition -fm tmpimage 2 81:$rootsects* 0:0 81:$usrsects
38 installboot -m tmpimage /usr/mdec/masterboot
39 dd < tmpimage > subpart count=1
41 primsects=`expr 1 + $rootsects + $usrsects`
42 cyl=`expr '(' $primsects ')' / $secs + 1`
43 padsects=`expr $cyl \* $secs - 1 - $primsects`
45 { dd < /dev/zero count=1
46 cat subpart
47 cat rootimage
48 cat usrimage
49 dd < /dev/zero count=$padsects
50 } > hdimage
51 partition -m hdimage 81:`expr $primsects + $padsects`*
52 installboot -m hdimage /usr/mdec/masterboot
55 retrieve()
57 dir=$1
58 list=`pwd`/$2
59 url=http://www.minix3.org/$3
60 BIGPORTS=bigports
62 cd $dir || exit 1
63 echo " * Updating $dir
64 from $url
65 with $list"
66 files=`awk <$list '{ print "'$url'/" $1 ".tar.bz2" }'`
67 wget -c $url/List $files || true
71 hdemu_root_changes()
73 $RELEASEDIR/usr/bin/installboot -d $TMPDISK3 \
74 $RELEASEDIR/usr/mdec/bootblock boot/boot
75 echo \
76 'bootcd=2
77 disable=inet
78 bios_wini=yes
79 bios_remap_first=1
80 ramimagedev=c0d7p0s0
81 bootbig(1, Regular MINIX 3) { image=/boot/image_big; boot }
82 main() { trap 10000 boot ; menu; }
83 save' | $RELEASEDIR/usr/bin/edparams $TMPDISK3
85 echo \
86 'root=/dev/c0d7p0s0
87 usr=/dev/c0d7p0s2
88 usr_roflag="-r"' > $RELEASEDIR/etc/fstab
91 usb_root_changes()
93 $RELEASEDIR/usr/bin/installboot -d $TMPDISK3 \
94 $RELEASEDIR/usr/mdec/bootblock boot/boot
95 echo \
96 'bios_wini=yes
97 bios_remap_first=1
98 rootdev=c0d7p0s0
99 save' | $RELEASEDIR/usr/bin/edparams $TMPDISK3
101 echo \
102 'root=/dev/c0d7p0s0
103 usr=/dev/c0d7p0s2
104 ' > $RELEASEDIR/etc/fstab
107 RELEASEDIR=/usr/r
108 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
109 RELEASEPACKAGESOURCES=${RELEASEDIR}/usr/install/package-sources
110 IMAGE=../boot/boot
111 ROOTIMAGE=rootimage
112 CDFILES=/usr/tmp/cdreleasefiles
113 sh tell_config OS_RELEASE . OS_VERSION >/tmp/rel.$$
114 version_pretty=`sed 's/[" ]//g;/^$/d' </tmp/rel.$$`
115 version=`sed 's/[" ]//g;/^$/d' </tmp/rel.$$ | tr . _`
116 IMG_BASE=minix${version}_ide
117 BS=4096
119 HDEMU=0
120 COPY=0
121 SVNREV=""
122 REVTAG=""
123 PACKAGES=1
125 FILENAMEOUT=""
127 while getopts "s:pchu?r:f:" c
129 case "$c" in
131 echo "Usage: $0 [-p] [-c] [-h] [-r <tag>] [-u] [-f <filename>] [-s <username>]" >&2
132 exit 1
135 echo " * Making HD image"
136 IMG_BASE=minix${version}_bios
137 HDEMU=1
140 echo " * Copying, not SVN"
141 COPY=1
144 PACKAGES=0
147 SVNREV=-r$OPTARG
150 echo " * Making live USB-stick image"
151 IMG_BASE=minix${version}_usb
152 HDEMU=1
153 USB=1
156 FILENAMEOUT="$OPTARG"
158 s) USERNAME="--username=$OPTARG"
160 esac
161 done
163 if [ ! "$USRMB" ]
164 then USRMB=600
167 if [ $PACKAGES -ne 0 ]
168 then mkdir -p $PACKAGEDIR || true
169 mkdir -p $PACKAGESOURCEDIR || true
170 rm -f $PACKAGEDIR/List
171 retrieve $PACKAGEDIR $PACKAGELIST packages/`uname -p`/`uname -r`.`uname -v`
172 retrieve $PACKAGESOURCEDIR $PACKAGESOURCELIST software
175 echo $USRMB MB
177 USRKB=$(($USRMB*1024))
178 USRBLOCKS=$(($USRMB * 1024 * 1024 / $BS))
179 USRSECTS=$(($USRMB * 1024 * 2))
180 ROOTKB=8192
181 ROOTSECTS=$(($ROOTKB * 2))
182 ROOTBLOCKS=$(($ROOTKB * 1024 / $BS))
184 if [ "$COPY" -ne 1 ]
185 then
186 echo "Note: this script wants to do svn operations."
189 TMPDISK1=/dev/ram0
190 TMPDISK2=/dev/ram1
191 TMPDISK3=/dev/ram2
193 if [ ! -b $TMPDISK1 -o ! -b $TMPDISK2 -o ! $TMPDISK3 ]
194 then echo "$TMPDISK1, $TMPDISK2 or $TMPDISK3 is not a block device.."
195 exit 1
198 umount $TMPDISK1 || true
199 umount $TMPDISK2 || true
200 umount $TMPDISK3 || true
202 ramdisk $USRKB $TMPDISK1
203 ramdisk $TMPKB $TMPDISK2
204 ramdisk $ROOTKB $TMPDISK3
206 if [ $TMPDISK1 = $TMPDISK2 -o $TMPDISK1 = $TMPDISK3 -o $TMPDISK2 = $TMPDISK3 ]
207 then
208 echo "Temporary devices can't be equal."
209 exit
212 echo " * Cleanup old files"
213 rm -rf $RELEASEDIR $IMG $ROOTIMAGE $CDFILES image*
214 mkdir -p $CDFILES || exit
215 mkdir -p $RELEASEDIR
216 mkfs -i 2000 -B $BS -b $ROOTBLOCKS $TMPDISK3 || exit
217 mkfs -B 1024 -b $TMPKB $TMPDISK2 || exit
218 echo " * mounting $TMPDISK3 as $RELEASEDIR"
219 mount $TMPDISK3 $RELEASEDIR || exit
220 mkdir -m 755 $RELEASEDIR/usr
221 mkdir -m 1777 $RELEASEDIR/tmp
222 mount $TMPDISK2 $RELEASEDIR/tmp
224 mkfs -B $BS -i 30000 -b $USRBLOCKS $TMPDISK1 || exit
225 echo " * Mounting $TMPDISK1 as $RELEASEDIR/usr"
226 mount $TMPDISK1 $RELEASEDIR/usr || exit
227 mkdir -p $RELEASEDIR/tmp
228 mkdir -p $RELEASEDIR/usr/tmp
229 mkdir -p $RELEASEDIR/$XBIN
230 mkdir -p $RELEASEDIR/usr/bin
231 mkdir -p $RELEASEDIR/bin
232 mkdir -p $RELEASEPACKAGE
233 mkdir -p $RELEASEPACKAGESOURCES
235 echo " * Transfering bootstrap dirs to $RELEASEDIR"
236 cp -p /bin/* /usr/bin/* $RELEASEDIR/$XBIN
237 cp -rp /usr/lib $RELEASEDIR/usr
238 cp -rp /bin/bigsh /bin/sh /bin/echo $RELEASEDIR/bin
239 cp -rp /usr/bin/make /usr/bin/install /usr/bin/yacc /usr/bin/flex /usr/bin/asmconv $RELEASEDIR/usr/bin
241 if [ -d $PACKAGEDIR -a -d $PACKAGESOURCEDIR -a -f $PACKAGELIST -a -f $PACKAGESOURCELIST -a $PACKAGES -ne 0 ]
242 then echo " * Transfering $PACKAGEDIR to $RELEASEPACKAGE"
243 : >$RELEASEPACKAGE/List
244 for p in `cat $PACKAGELIST`
245 do if [ -f $PACKAGEDIR/$p.tar.bz2 ]
246 then
247 cp $PACKAGEDIR/$p.tar.bz2 $RELEASEPACKAGE/
248 grep "^$p|" $PACKAGEDIR/List >>$RELEASEPACKAGE/List || echo "$p not found in List"
249 else
250 echo "Can't copy $PACKAGEDIR/$p.tar.bz2. Missing."
252 done
254 echo " * Transfering $PACKAGESOURCEDIR to $RELEASEPACKAGESOURCES"
255 for p in `cat $PACKAGESOURCELIST`
257 if [ -f $PACKAGESOURCEDIR/$p.tar.bz2 ]
258 then
259 cp $PACKAGESOURCEDIR/$p.tar.bz2 $RELEASEPACKAGESOURCES/
260 else
261 echo "Can't copy $PACKAGESOURCEDIR/$p.tar.bz2. Missing."
263 done
266 # Make sure compilers and libraries are bin-owned
267 chown -R bin $RELEASEDIR/usr/lib
268 chmod -R u+w $RELEASEDIR/usr/lib
270 if [ "$COPY" -ne 1 ]
271 then
272 echo " * Doing new svn export"
273 TOOLSREPO="`svn info | grep '^URL: ' | awk '{ print $2 }'`"
274 REPO="`echo $TOOLSREPO | sed 's/.tools$//'`"
275 BRANCHNAME="`echo $REPO | awk -F/ '{ print $NF }'`"
276 REVISION="`svn info $USERNAME $SVNREV $REPO | grep '^Revision: ' | awk '{ print $2 }'`"
277 echo "Doing export of revision $REVISION from $REPO."
278 ( cd $RELEASEDIR/usr && svn -q $USERNAME export -r$REVISION $REPO $SRC )
279 if [ $BRANCHNAME = src ]
280 then REVTAG=r$REVISION
281 else REVTAG=branch-$BRANCHNAME-r$REVISION
284 echo "
286 /* Added by release script */
287 #ifndef _SVN_REVISION
288 #define _SVN_REVISION \"$REVTAG\"
289 #endif" >>$RELEASEDIR/usr/src/include/minix/sys_config.h
291 # output image name
292 if [ "$USB" -ne 0 ]; then
293 IMG=${IMG_BASE}_${REVTAG}.img
294 else
295 IMG=${IMG_BASE}_${REVTAG}.iso
298 else
299 ( cd .. && make depend && make clean )
300 srcdir=/usr/$SRC
301 ( cd $srcdir && tar cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
302 REVTAG=copy
303 REVISION=unknown
304 IMG=${IMG_BASE}_copy.iso
307 echo " * Fixups for owners and modes of dirs and files"
308 chown -R bin $RELEASEDIR/usr/$SRC
309 chmod -R u+w $RELEASEDIR/usr/$SRC
310 find $RELEASEDIR/usr/$SRC -type d | xargs chmod 755
311 find $RELEASEDIR/usr/$SRC -type f | xargs chmod 644
312 find $RELEASEDIR/usr/$SRC -name configure | xargs chmod 755
313 find $RELEASEDIR/usr/$SRC/commands -name build | xargs chmod 755
314 # Bug tracking system not for on cd
315 rm -rf $RELEASEDIR/usr/$SRC/doc/bugs
317 # Make sure the CD knows it's a CD, unless it's not
318 if [ "$USB" -eq 0 ]
319 then date >$RELEASEDIR/CD
321 echo " * Bootstrap /etc/mk files"
322 # Need /etc/mk in the new system to invoke make. Real ownerships
323 # and permissions will be set by its own src/etc/Makefile.
324 # They have to be owned by bin so that the new make can do its work.
325 mkdir -p $RELEASEDIR/etc/mk
326 chmod 755 $RELEASEDIR/etc/mk
327 cp $RELEASEDIR/usr/src/etc/mk/* $RELEASEDIR/etc/mk/
328 chown -R bin $RELEASEDIR/etc/mk
329 echo " * Chroot build"
330 cp chrootmake.sh $RELEASEDIR/usr/$SRC/tools/chrootmake.sh
331 chroot $RELEASEDIR "PATH=/$XBIN sh -x /usr/$SRC/tools/chrootmake.sh" || exit 1
332 # Copy built images for cd booting
333 cp $RELEASEDIR/boot/image_big image
334 echo " * Chroot build done"
335 echo " * Removing bootstrap files"
336 rm -rf $RELEASEDIR/$XBIN
337 # The build process leaves some file in $SRC as root.
338 chown -R bin $RELEASEDIR/usr/src*
339 cp issue.install $RELEASEDIR/etc/issue
341 if [ "$USB" -ne 0 ]
342 then
343 usb_root_changes
344 elif [ "$HDEMU" -ne 0 ]
345 then
346 hdemu_root_changes
349 echo $version_pretty, SVN revision $REVISION, generated `date` >$RELEASEDIR/etc/version
350 echo " * Counting files"
351 extrakb=`du -s $RELEASEDIR/usr/install | awk '{ print $1 }'`
352 expr `df $TMPDISK1 | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEDIR/.usrkb
353 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
354 find $RELEASEDIR -xdev | wc -l >$RELEASEDIR/.rootfiles
355 echo " * Zeroing remainder of temporary areas"
356 df $TMPDISK1
357 df $TMPDISK3
358 cp /dev/zero $RELEASEDIR/usr/.x 2>/dev/null || true
359 rm $RELEASEDIR/usr/.x
360 cp /dev/zero $RELEASEDIR/.x 2>/dev/null || true
361 rm $RELEASEDIR/.x
363 umount $TMPDISK1 || exit
364 umount $TMPDISK2 || exit
365 umount $TMPDISK3 || exit
367 # Boot monitor variables for boot CD
368 edparams $TMPDISK3 'unset bootopts;
369 unset servers;
370 unset rootdev;
371 unset leader;
372 unset image;
373 disable=inet;
374 bootcd=1;
375 cdproberoot=1;
376 ata_id_timeout=2;
377 bootbig(1, Regular MINIX 3) { unset image; boot }
378 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; };
379 save'
381 (cd ../boot && make)
382 dd if=$TMPDISK3 of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
383 cp release/cd/* $CDFILES || true
384 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
386 boottype=-n
387 bootimage=$IMAGE
388 if [ "$HDEMU" -ne 0 ]; then
389 make_hdimage
390 boottype='-h'
391 bootimage=hdimage
394 if [ "$USB" -ne 0 ]; then
395 mv $bootimage $IMG
396 else
397 writeisofs -s0x1000 -l MINIX -b $bootimage $boottype $CDFILES $IMG || exit 1
399 if [ "$HDEMU" -eq 0 ]
400 then
401 echo "Appending Minix root and usr filesystem"
402 # Pad ISO out to cylinder boundary
403 isobytes=`stat -size $IMG`
404 isosects=`expr $isobytes / 512`
405 isopad=`expr $secs - '(' $isosects % $secs ')'`
406 dd if=/dev/zero count=$isopad >>$IMG
407 # number of sectors
408 isosects=`expr $isosects + $isopad`
409 ( cat $IMG $ROOTIMAGE ;
410 dd if=$TMPDISK1 bs=$BS count=$USRBLOCKS ) >m
411 mv m $IMG
412 # Make CD partition table
413 installboot -m $IMG /usr/mdec/masterboot
414 # Make sure there is no hole..! Otherwise the ISO format is
415 # unreadable.
416 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
420 if [ "$FILENAMEOUT" ]
421 then echo "$IMG" >$FILENAMEOUT