Include svn revision number in iso filename when doing build
[minix3.git] / tools / release.sh
blobd3fdd210684f93103da14d627b2313f82bfd88f9
1 #!/bin/sh
3 set -e
5 XBIN=usr/xbin
6 SRC=src
8 PACKAGEDIR=/usr/bigports/Packages
9 PACKAGESOURCEDIR=/usr/bigports/Sources
10 secs=`expr 32 '*' 64`
11 export SHELL=/bin/sh
13 make_hdimage()
15 dd if=$TMPDISK of=usrimage bs=$BS count=$USRBLOCKS
17 rootsize=`stat -size rootimage`
18 usrsize=`stat -size usrimage`
20 rootsects=`expr $rootsize / 512`
21 usrsects=`expr $usrsize / 512`
23 # installboot -m needs at least 1KB
24 dd < /dev/zero >tmpimage count=2
25 partition -fm tmpimage 2 81:$rootsects* 0:0 81:$usrsects
26 installboot -m tmpimage /usr/mdec/masterboot
27 dd < tmpimage > subpart count=1
29 primsects=`expr 1 + $rootsects + $usrsects`
30 cyl=`expr '(' $primsects ')' / $secs + 1`
31 padsects=`expr $cyl \* $secs - 1 - $primsects`
33 { dd < /dev/zero count=1
34 cat subpart
35 cat rootimage
36 cat usrimage
37 dd < /dev/zero count=$padsects
38 } > hdimage
39 partition -m hdimage 81:`expr $primsects + $padsects`*
40 installboot -m hdimage /usr/mdec/masterboot
43 hdemu_root_changes()
45 $RELEASEDIR/usr/bin/installboot -d $TMPDISK3 \
46 $RELEASEDIR/usr/mdec/bootblock boot/boot
47 echo \
48 'bootcd=2
49 disable=inet
50 bios_wini=yes
51 bios_remap_first=1
52 ramimagedev=c0d7p0s0
53 bootbig(1, Regular MINIX 3) { image=/boot/image_big; boot }
54 bootsmall(2, Small MINIX 3 (<16MB)) {image=/boot/image_small; boot }
55 main() { trap 10000 boot ; menu; }
56 save' | $RELEASEDIR/usr/bin/edparams $TMPDISK3
58 echo \
59 'root=/dev/c0d7p0s0
60 usr=/dev/c0d7p0s2
61 usr_roflag="-r"' > $RELEASEDIR/etc/fstab
64 usb_root_changes()
66 $RELEASEDIR/usr/bin/installboot -d $TMPDISK3 \
67 $RELEASEDIR/usr/mdec/bootblock boot/boot
68 echo \
69 'bios_wini=yes
70 bios_remap_first=1
71 rootdev=c0d7p0s0
72 save' | $RELEASEDIR/usr/bin/edparams $TMPDISK3
74 echo \
75 'root=/dev/c0d7p0s0
76 usr=/dev/c0d7p0s2
77 ' > $RELEASEDIR/etc/fstab
80 RELEASEDIR=/usr/r
81 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
82 RELEASEPACKAGESOURCES=${RELEASEDIR}/usr/install/package-sources
83 IMAGE=cdfdimage
84 ROOTIMAGE=rootimage
85 CDFILES=/usr/tmp/cdreleasefiles
86 sh tell_config OS_RELEASE . OS_VERSION >/tmp/rel.$$
87 version_pretty=`sed 's/[" ]//g;/^$/d' </tmp/rel.$$`
88 version=`sed 's/[" ]//g;/^$/d' </tmp/rel.$$ | tr . _`
89 IMG_BASE=minix${version}_ide
90 BS=4096
92 HDEMU=0
93 COPY=0
94 SVNREV=""
95 REVTAG=""
96 PACKAGES=1
98 while getopts "pchu?r:" c
100 case "$c" in
102 echo "Usage: $0 [-p] [-c] [-h] [-r <tag>] [-u]" >&2
103 exit 1
106 echo " * Making HD image"
107 IMG_BASE=minix${version}_bios
108 HDEMU=1
111 echo " * Copying, not SVN"
112 COPY=1
115 PACKAGES=0
118 SVNREV=-r$OPTARG
121 echo " * Making live USB-stick image"
122 IMG_BASE=minix${version}_usb
123 HDEMU=1
124 USB=1
126 esac
127 done
129 USRMB=400
131 USRBLOCKS="`expr $USRMB \* 1024 \* 1024 / $BS`"
132 USRSECTS="`expr $USRMB \* 1024 \* 2`"
133 ROOTKB=4096
134 ROOTSECTS="`expr $ROOTKB \* 2`"
135 ROOTBLOCKS="`expr $ROOTKB \* 1024 / $BS`"
137 if [ "$COPY" -ne 1 ]
138 then
139 echo "Note: this script wants to do svn operations."
142 TD1=.td1
143 TD2=.td2
144 TD3=.td3
147 if [ -f $TD1 ]
148 then TMPDISK="`cat $TD1`"
149 echo " * Warning: I'm going to overwrite $TMPDISK!"
150 else
151 echo "Temporary (sub)partition to use to make the /usr FS image? "
152 echo "I need $USRMB MB. It will be mkfsed!"
153 echo -n "Device: /dev/"
154 read dev || exit 1
155 TMPDISK=/dev/$dev
158 if [ -b $TMPDISK ]
159 then :
160 else echo "$TMPDISK is not a block device.."
161 exit 1
164 echo $TMPDISK >$TD1
166 if [ -f $TD2 ]
167 then TMPDISK2="`cat $TD2`"
168 echo " * Warning: I'm going to overwrite $TMPDISK2!"
169 else
170 echo "Temporary (sub)partition to use for /tmp? "
171 echo "It will be mkfsed!"
172 echo -n "Device: /dev/"
173 read dev || exit 1
174 TMPDISK2=/dev/$dev
177 if [ -b $TMPDISK2 ]
178 then :
179 else echo "$TMPDISK2 is not a block device.."
180 exit 1
183 echo $TMPDISK2 >$TD2
185 if [ -f $TD3 ]
186 then TMPDISK3="`cat $TD3`"
187 echo " * Warning: I'm going to overwrite $TMPDISK3!"
188 else
189 echo "It has to be at least $ROOTKB KB."
190 echo ""
191 echo "Temporary (sub)partition to use to make the root FS image? "
192 echo "It will be mkfsed!"
193 echo -n "Device: /dev/"
194 read dev || exit 1
195 TMPDISK3=/dev/$dev
198 if [ -b $TMPDISK3 ]
199 then :
200 else echo "$TMPDISK3 is not a block device.."
201 exit 1
204 echo $TMPDISK3 >$TD3
206 umount $TMPDISK || true
207 umount $TMPDISK2 || true
208 umount $TMPDISK3 || true
210 if [ $TMPDISK = $TMPDISK2 -o $TMPDISK = $TMPDISK3 -o $TMPDISK2 = $TMPDISK3 ]
211 then
212 echo "Temporary devices can't be equal."
213 exit
216 echo " * Cleanup old files"
217 rm -rf $RELEASEDIR $IMG $IMAGE $ROOTIMAGE $IMGBZ $CDFILES image*
218 mkdir -p $CDFILES || exit
219 mkdir -p $RELEASEDIR
220 mkfs -B $BS -b $ROOTBLOCKS $TMPDISK3 || exit
221 mkfs $TMPDISK2 || exit
222 echo " * mounting $TMPDISK3 as $RELEASEDIR"
223 mount $TMPDISK3 $RELEASEDIR || exit
224 mkdir -m 755 $RELEASEDIR/usr
225 mkdir -m 1777 $RELEASEDIR/tmp
226 mount $TMPDISK2 $RELEASEDIR/tmp
228 mkfs -B $BS -b $USRBLOCKS $TMPDISK || exit
229 echo " * Mounting $TMPDISK as $RELEASEDIR/usr"
230 mount $TMPDISK $RELEASEDIR/usr || exit
231 mkdir -p $RELEASEDIR/tmp
232 mkdir -p $RELEASEDIR/usr/tmp
233 mkdir -p $RELEASEDIR/$XBIN
234 mkdir -p $RELEASEDIR/usr/bin
235 mkdir -p $RELEASEDIR/bin
236 mkdir -p $RELEASEPACKAGE
237 mkdir -p $RELEASEPACKAGESOURCES
239 echo " * Transfering bootstrap dirs to $RELEASEDIR"
240 cp -p /bin/* /usr/bin/* $RELEASEDIR/$XBIN
241 cp -rp /usr/lib $RELEASEDIR/usr
242 cp -rp /bin/bigsh /bin/sh $RELEASEDIR/bin
243 cp -rp /usr/bin/make /usr/bin/install /usr/bin/yacc /usr/bin/flex $RELEASEDIR/usr/bin
245 if [ -d $PACKAGEDIR -a -d $PACKAGESOURCEDIR -a $PACKAGES -ne 0 ]
246 then echo " * Indexing packages"
247 bintotal=0
248 ( cd $PACKAGEDIR
249 for p in *.tar.bz2
250 do echo $p >&2
251 p="`echo $p | sed 's/.tar.bz2//'`"
252 descr="../$p/.descr"
253 if [ -f "$descr" ]
254 then echo "$p|`cat $descr`"
256 done >List
258 for d in $PACKAGEDIR $PACKAGESOURCEDIR
259 do echo Counting size of $d
260 f=$d/SizeMB
261 if [ ! -f $f ]
262 then
263 b="`bzip2 -dc $d/*.bz2 | wc -c`"
264 echo "`expr 1 + $b / 1024 / 1024`" >$f
266 echo "`cat $f` MB."
267 done
268 echo " * Transfering $PACKAGEDIR to $RELEASEPACKAGE"
269 cp $PACKAGEDIR/* $RELEASEPACKAGE/
270 echo " * Transfering $PACKAGESOURCEDIR to $RELEASEPACKAGESOURCES"
271 cp $PACKAGESOURCEDIR/* $RELEASEPACKAGESOURCES/ || true
275 # Make sure compilers and libraries are bin-owned
276 chown -R bin $RELEASEDIR/usr/lib
277 chmod -R u+w $RELEASEDIR/usr/lib
279 if [ "$COPY" -ne 1 ]
280 then
281 echo " * Doing new svn export"
282 REPO=https://gforge.cs.vu.nl/svn/minix/trunk/$SRC
283 REVISION="`svn info $SVNREV $REPO | grep '^Revision: ' | awk '{ print $2 }'`"
284 echo "Doing export of revision $REVISION from $REPO."
285 ( cd $RELEASEDIR/usr && svn export -r$REVISION $REPO )
286 REVTAG=r$REVISION
287 else
288 ( cd .. && make depend && make clean )
289 srcdir=/usr/$SRC
290 ( cd $srcdir && tar cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
291 REVTAG=copy
294 if [ "$USB" -ne 0 ]; then
295 IMG=${IMG_BASE}_${REVTAG}.img
296 else
297 IMG=${IMG_BASE}_${REVTAG}.iso
299 IMGBZ=${IMG}.bz2
300 echo "Making $IMGBZ"
302 echo " * Fixups for owners and modes of dirs and files"
303 chown -R bin $RELEASEDIR/usr/$SRC
304 chmod -R u+w $RELEASEDIR/usr/$SRC
305 find $RELEASEDIR/usr/$SRC -type d | xargs chmod 755
306 find $RELEASEDIR/usr/$SRC -type f | xargs chmod 644
307 find $RELEASEDIR/usr/$SRC -name configure | xargs chmod 755
308 find $RELEASEDIR/usr/$SRC/commands -name build | xargs chmod 755
309 # Bug tracking system not for on cd
310 rm -rf $RELEASEDIR/usr/$SRC/doc/bugs
312 # Make sure the CD knows it's a CD, unless it's not
313 if [ "$USB" -eq 0 ]
314 then date >$RELEASEDIR/CD
316 echo " * Chroot build"
317 chroot $RELEASEDIR "PATH=/$XBIN sh -x /usr/$SRC/tools/chrootmake.sh" || exit 1
318 echo " * Chroot build done"
319 echo " * Removing bootstrap files"
320 rm -rf $RELEASEDIR/$XBIN
321 # The build process leaves some file in $SRC as root.
322 chown -R bin $RELEASEDIR/usr/src*
323 cp issue.install $RELEASEDIR/etc/issue
325 if [ "$USB" -ne 0 ]
326 then
327 usb_root_changes
328 elif [ "$HDEMU" -ne 0 ]
329 then
330 hdemu_root_changes
333 echo $version_pretty >$RELEASEDIR/etc/version
334 echo " * Counting files"
335 extrakb=`du -s $RELEASEDIR/usr/install | awk '{ print $1 }'`
336 expr `df $TMPDISK | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEDIR/.usrkb
337 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
338 find $RELEASEDIR -xdev | wc -l >$RELEASEDIR/.rootfiles
339 echo " * Zeroing remainder of temporary areas"
340 df $TMPDISK
341 df $TMPDISK3
342 cp /dev/zero $RELEASEDIR/usr/.x 2>/dev/null || true
343 rm $RELEASEDIR/usr/.x
344 cp /dev/zero $RELEASEDIR/.x 2>/dev/null || true
345 rm $RELEASEDIR/.x
347 umount $TMPDISK || exit
348 umount $TMPDISK2 || exit
349 umount $TMPDISK3 || exit
350 (cd ../boot && make)
351 (cd .. && make depend)
352 make clean
353 make image || exit 1
354 mv image image_big
355 make clean
356 make image_small || exit 1
357 dd if=$TMPDISK3 of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
358 # Prepare image and image_small for cdfdboot
359 mv image_big image
360 sh mkboot cdfdboot $TMPDISK3
361 cp $IMAGE $CDFILES/bootflop.img
362 cp release/cd/* $CDFILES || true
363 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
365 h_opt=
366 bootimage=$IMAGE
367 if [ "$HDEMU" -ne 0 ]; then
368 make_hdimage
369 h_opt='-h'
370 bootimage=hdimage
373 if [ "$USB" -ne 0 ]; then
374 mv $bootimage $IMG
375 else
376 writeisofs -l MINIX -b $bootimage $h_opt $CDFILES $IMG || exit 1
378 if [ "$HDEMU" -eq 0 ]
379 then
380 echo "Appending Minix root and usr filesystem"
381 # Pad ISO out to cylinder boundary
382 isobytes=`stat -size $IMG`
383 isosects=`expr $isobytes / 512`
384 isopad=`expr $secs - '(' $isosects % $secs ')'`
385 dd if=/dev/zero count=$isopad >>$IMG
386 # number of sectors
387 isosects=`expr $isosects + $isopad`
388 ( cat $IMG $ROOTIMAGE ;
389 dd if=$TMPDISK bs=$BS count=$USRBLOCKS ) >m
390 mv m $IMG
391 # Make CD partition table
392 installboot -m $IMG /usr/mdec/masterboot
393 # Make sure there is no hole..! Otherwise the ISO format is
394 # unreadable.
395 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS