include: reduce default stack size
[minix.git] / releasetools / release.sh
blobd0b729891572381080289e77994dd96aab4602ed
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
51 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
53 IMAGE=/usr/mdec/bootxx_cd9660
54 ROOTIMAGE=rootimage
55 CDFILES=/usr/tmp/cdreleasefiles
56 sh tell_config OS_RELEASE . OS_VERSION >/tmp/rel.$$
57 IMG_BASE=minix${version}_ide
58 BS=4096
60 HDEMU=0
61 COPY=0
62 JAILMODE=0
63 REVTAG=""
64 PACKAGES=1
65 MINIMAL=0
66 MAKEMAP=0
67 EXTRAS_INSTALL=0
68 EXTRAS_PATH=
70 # Do we have git?
71 if git --version >/dev/null
72 then if [ -d ../.git ]
73 then LOCAL_REVTAG="`git describe --always`"
74 GITMODE=1
78 FILENAMEOUT=""
80 while getopts "b:j:ls:pmMchu?f:L:e:" c
82 case "$c" in
83 \?)
84 echo "Usage: $0 [-l] [-p] [-c] [-h] [-m] [-M] [-u] [-f <filename>] [-s <username>] -j<jaildir> [-L <packageurl>] [-e <extras-path>]" >&2
85 exit 1
88 GITBRANCH=$OPTARG
91 echo " * Making HD image"
92 IMG_BASE=minix${version}_bios
93 HDEMU=1
96 echo " * Copying, not using GIT"
97 COPY=1
100 PACKAGES=0
103 RELEASEDIR=$OPTARG
104 JAILMODE=1
107 echo " * Making live USB-stick image"
108 IMG_BASE=minix${version}_usb
109 HDEMU=1
110 USB=1
113 FILENAMEOUT="$OPTARG"
115 s) USERNAME="--username=$OPTARG"
117 m) MINIMAL=1
118 PACKAGES=0
120 M) MAKEMAP=1
122 l) PKG_ADD_URL=file://$PACKAGEDIR/All
124 L) PKG_ADD_URL="$OPTARG"
125 CUSTOM_PACKAGES=1
127 e) EXTRAS_INSTALL=1
128 EXTRAS_PATH="$OPTARG"
130 esac
131 done
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 "Copying contents from current src dir."
209 ( cd .. && make cleandir )
210 srcdir=/usr/$SRC
211 ( cd $srcdir && tar --exclude .svn -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
212 REVTAG=copy
213 REVISION=unknown
214 IMG=${IMG_BASE}_copy.iso
217 # Make sure the CD knows it's a CD, unless it's not
218 if [ "$USB" -eq 0 ]
219 then date >$RELEASEDIR/CD
222 rm -f $RELEASEDIR/usr/$SRC/releasetools/revision
224 for p in $PREINSTALLED_PACKAGES
225 do echo " * Pre-installing: $p from $PKG_ADD_URL"
226 $PKG_ADD -f -P $RELEASEDIR $PKG_ADD_URL/$p
227 done
229 if [ "$CUSTOM_PACKAGES" ]
230 then echo $PKG_ADD_URL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
233 echo " * Resetting timestamps"
234 find $RELEASEDIR | xargs touch
236 ##########################################################################
237 echo " * Build"
238 ##########################################################################
240 cd $RELEASEDIR/usr/src
241 make distribution DESTDIR=$RELEASEDIR CHECKFLIST=no
242 make -C releasetools do-hdboot DESTDIR=$RELEASEDIR MKINSTALLBOOT=yes
243 cp $RELEASEDIR/usr/mdec/boot_monitor $RELEASEDIR
244 cp $RELEASEDIR/boot/minix_latest/* $RELEASEDIR/boot/minix_default/
246 if [ $MAKEMAP -ne 0 ]; then
247 find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
249 make cleandir
251 cd -
253 echo " * build done"
255 ##########################################################################
256 echo " * Removing bootstrap files"
257 ##########################################################################
258 # The build process leaves some file in $SRC as bin.
259 chown -R root $RELEASEDIR/usr/src*
260 cp issue.install $RELEASEDIR/etc/issue
262 echo $version_pretty, SVN revision $REVISION, generated `date` >$RELEASEDIR/etc/version
263 rm -rf $RELEASEDIR/tmp/*
265 if [ $MINIMAL -ne 0 ]
266 then
267 if [ "$MAKEMAP" -ne 0 ]
268 then
269 echo " * Copying symbol map to ${IMG}-symbols.txt"
270 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
271 $ZIP -f ${IMG}-symbols.txt
274 echo " * Removing files to create minimal image"
275 rm -rf $RELEASEDIR/usr/man/man*/* \
276 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
277 mkdir -p $RELEASEDIR/usr/src/releasetools
280 if [ $EXTRAS_INSTALL -ne 0 ] ; then
281 echo " * Copying files from $EXTRAS_PATH"
282 cp -Rv $EXTRAS_PATH/* $RELEASEDIR
285 # If we are making a jail, all is done!
286 if [ $JAILMODE = 1 ]
287 then echo "Created new minix install in $RELEASEDIR."
288 echo "Enter it by typing: "
289 echo "# chroot $RELEASEDIR /bin/sh"
290 exit 0
293 ##########################################################################
294 echo " * Counting files"
295 ##########################################################################
296 extrakb=`du -ks $RELEASEDIR/usr/install | awk '{ print $1 }'`
297 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
298 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
300 fstab_marker="# Poor man's File System Table."
301 echo " * Writing fstab"
302 if [ "$USB" -ne 0 ]
303 then
304 echo \
305 "$fstab_marker
306 root=/dev/c0d7p0s0
307 usr=/dev/c0d7p0s2
308 " > $RELEASEDIR/etc/fstab
309 elif [ "$HDEMU" -ne 0 ]
310 then
311 echo \
312 "$fstab_marker
313 root=/dev/c0d7p0s0
314 usr=/dev/c0d7p0s2
315 usr_roflag=\"-r\"" > $RELEASEDIR/etc/fstab
318 ##########################################################################
319 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
320 ##########################################################################
321 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
322 ROOTBLOCKS=$blocks
323 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
324 mount $TMPDISKROOT $RELEASEMNTDIR || exit
326 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
327 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
328 USRBLOCKS=$blocks
329 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
330 mkdir -m 755 $RELEASEMNTDIR/usr
331 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
333 ##########################################################################
334 echo " * Copying files from staging to image"
335 ##########################################################################
336 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
337 expr `df -k $TMPDISKUSR | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
339 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
340 umount $TMPDISKUSR || exit
342 echo " * Making image bootable"
343 if [ "$USB" -ne 0 ]
344 then
345 usb_root_changes
346 elif [ "$HDEMU" -ne 0 ]
347 then
348 hdemu_root_changes
349 else
350 cd_root_changes
353 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
354 umount $TMPDISKROOT || exit
355 rm -r $RELEASEMNTDIR
357 ##########################################################################
358 echo " * Generating image files"
359 ##########################################################################
360 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
361 cp release/cd/* $CDFILES || true
362 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
364 boottype=-n
365 bootimage=$IMAGE
366 if [ "$HDEMU" -ne 0 ]; then
367 make_hdimage
368 boottype='-h'
369 bootimage=hdimage
372 if [ "$USB" -ne 0 ]; then
373 mv $bootimage $IMG
374 else
375 cp $RELEASEDIR/usr/mdec/boot_monitor $CDFILES/boot
376 cp -rf $RELEASEDIR/boot/minix_latest/* $CDFILES/
377 gzip -d $CDFILES/*gz
378 writeisofs -s0x0 -l MINIX -B $bootimage $boottype $CDFILES $IMG || exit 1
380 if [ "$HDEMU" -eq 0 ]
381 then
382 echo "Appending Minix root and usr filesystem"
383 # Pad ISO out to cylinder boundary
384 isobytes=`stat -f %z $IMG`
385 isosects=`expr $isobytes / 512`
386 isopad=`expr $secs - '(' $isosects % $secs ')'`
387 dd if=/dev/zero count=$isopad >>$IMG
388 # number of sectors
389 isosects=`expr $isosects + $isopad`
390 ( cat $IMG $ROOTIMAGE ;
391 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
392 mv m $IMG
393 # Make CD partition table
394 installboot_nbsd -m $IMG /usr/mdec/mbr
395 # Make sure there is no hole..! Otherwise the ISO format is
396 # unreadable.
397 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
401 # Clean up: RELEASEDIR no longer needed
402 rm -r $RELEASEDIR
404 echo "${ZIP}ping $IMG"
405 $ZIP -f $IMG
407 if [ "$FILENAMEOUT" ]
408 then echo "$IMG" >$FILENAMEOUT
411 ##########################################################################
412 echo " * Freeing up memory used by ramdisks"
413 ##########################################################################
414 ramdisk 1 $TMPDISKROOT
415 ramdisk 1 $TMPDISKUSR