custom message for vm_query_exit
[minix3.git] / releasetools / release.sh
blob80b2b78c839c54a5033eb561c6463bb5918c7c8c
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}
14 : ${BUILDOPTIONS:=}
16 # List of packages included on installation media
17 PACKAGELIST=packages.install
18 secs=`expr 32 '*' 64`
19 export SHELL=/bin/sh
21 PKG_ADD=/usr/pkg/sbin/pkg_add
22 PKG_INFO=/usr/pkg/sbin/pkg_info
24 if [ ! -x $PKG_ADD ]
25 then echo Please install pkg_install from pkgsrc.
26 exit 1
29 # Packages we have to pre-install, and url to use
30 PACKAGEURL=ftp://ftp.minix3.org/pub/minix/packages/$version_pretty/`uname -m`/All/
31 PREINSTALLED_PACKAGES="
32 pkg_install
33 pkgin
34 bmake
35 binutils
36 clang
38 # pkg_tarup
40 PKG_ADD_URL=$PACKAGEURL
42 RELEASERC=$HOME/.releaserc
44 if [ -f $RELEASERC ]
45 then . $RELEASERC
48 set -- $* $RELOPTS
50 export RELEASEDIR=/usr/r-staging
51 RELEASEMNTDIR=/usr/r
53 IMAGE=/usr/mdec/bootxx_cd9660
54 ROOTIMAGE=rootimage
55 CDFILES=/usr/tmp/cdreleasefiles
56 IMG_BASE=minix${version}_ide
57 BS=4096
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:lpmMch?f:L:e:" c
80 case "$c" in
81 \?)
82 echo "Usage: $0 [-l] [-p] [-c] [-m] [-M] [-f <filename>] -j<jaildir> [-L <packageurl>] [-e <extras-path>]" >&2
83 exit 1
86 GITBRANCH=$OPTARG
89 echo " * Copying, not using GIT"
90 COPY=1
93 PACKAGES=0
96 RELEASEDIR=$OPTARG
97 JAILMODE=1
100 FILENAMEOUT="$OPTARG"
102 m) MINIMAL=1
103 PACKAGES=0
105 M) MAKEMAP=1
107 l) PKG_ADD_URL=file://$PACKAGEDIR/All
109 L) PKG_ADD_URL="$OPTARG"
110 CUSTOM_PACKAGES=1
112 e) EXTRAS_INSTALL=1
113 EXTRAS_PATH="$OPTARG"
115 esac
116 done
118 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
120 if [ $GITMODE -ne 1 -a $COPY -ne 1 ]
121 then echo "Need git to retrieve latest minix! Copying src instead!"
122 COPY=1
125 if [ ! "$ZIP" ]
126 then ZIP=bzip2
129 if [ $PACKAGES -ne 0 ]
130 then mkdir -p $PACKAGEDIR/All || true
131 retrieve $PACKAGEDIR/All $PACKAGELIST packages/`uname -p`/$VERSION_PRETTY
134 TMPDISKUSR=/dev/ram0
135 TMPDISKROOT=/dev/ram1
137 if [ ! -b $TMPDISKUSR -o ! $TMPDISKROOT ]
138 then echo "$TMPDISKUSR or $TMPDISKROOT is not a block device.."
139 exit 1
142 if [ $TMPDISKUSR = $TMPDISKROOT ]
143 then
144 echo "Temporary devices can't be equal."
145 exit
148 if [ $JAILMODE = 0 ]
149 then echo " * Cleanup old files"
150 umount $TMPDISKUSR || true
151 umount $TMPDISKROOT || true
152 umount $RELEASEMNTDIR/usr || true
153 umount $RELEASEMNTDIR || true
156 rm -rf $RELEASEDIR $RELEASEMNTDIR $IMG $ROOTIMAGE $CDFILES image* || true
157 mkdir -p $CDFILES || exit
158 mkdir -p $RELEASEDIR $RELEASEMNTDIR
159 mkdir -p $RELEASEPACKAGE
161 ##########################################################################
162 echo " * Bootstrapping filesystem in $RELEASEDIR"
163 ##########################################################################
164 CONFIGHEADER=$RELEASEDIR/usr/src/include/minix/sys_config.h
166 copy_local_packages
168 if [ "$COPY" -ne 1 ]
169 then
170 echo "Retrieving latest minix repo from $REPO branch $GITBRANCH."
171 srcdir=$RELEASEDIR/usr/src
172 git clone -b $GITBRANCH $REPO $srcdir
173 if [ "$REVTAG" ]
174 then echo "Doing checkout of $REVTAG."
175 (cd $srcdir && git checkout $REVTAG )
176 else REVTAG=`(cd $srcdir && git rev-parse --short HEAD)`
177 echo "Retrieved repository head in $srcdir is $REVTAG."
179 if [ $MINIMAL -ne 0 ]
180 then rm -r $srcdir/.git
182 echo "
183 /* Added by release script */
184 #ifndef _VCS_REVISION
185 #define _VCS_REVISION \"$REVTAG\"
186 #endif" >>$CONFIGHEADER
187 DATE=`date +%Y%m%d`
188 # output image name
189 IMG=${IMG_BASE}_${DATE}_${REVTAG}.iso
190 else
191 echo "First cleaning current sourcedir.."
192 ( cd .. && make cleandir >/dev/null )
193 echo "Copying contents from current src dir."
194 srcdir=/usr/$SRC
195 ( cd $srcdir && tar --exclude .git -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
196 echo "Copying done."
197 REVTAG=copy
198 IMG=${IMG_BASE}_copy.iso
201 # Make sure the CD knows it's a CD, unless it's not
202 date >$RELEASEDIR/CD
204 rm -f $RELEASEDIR/usr/$SRC/releasetools/revision
206 for p in $PREINSTALLED_PACKAGES
207 do echo " * Pre-installing: $p from $PKG_ADD_URL"
208 $PKG_ADD -f -P $RELEASEDIR $PKG_ADD_URL/$p
209 done
211 if [ "$CUSTOM_PACKAGES" ]
212 then echo $PKG_ADD_URL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
215 echo " * Resetting timestamps"
216 find $RELEASEDIR | xargs touch
218 ##########################################################################
219 echo " * Build"
220 ##########################################################################
222 cd $RELEASEDIR/usr/src
223 make distribution DESTDIR=$RELEASEDIR SLOPPY_FLIST=yes $BUILDOPTIONS
224 make -C releasetools do-hdboot DESTDIR=$RELEASEDIR MKINSTALLBOOT=yes
225 cp $RELEASEDIR/usr/mdec/boot_monitor $RELEASEDIR
226 cp $RELEASEDIR/boot/minix_latest/* $RELEASEDIR/boot/minix_default/
228 if [ $MAKEMAP -ne 0 ]; then
229 find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
231 make cleandir
233 cd -
235 echo " * build done"
237 ##########################################################################
238 echo " * Removing bootstrap files"
239 ##########################################################################
240 # The build process leaves some file in $SRC as bin.
241 chown -R root $RELEASEDIR/usr/src*
242 cp issue.install $RELEASEDIR/etc/issue
244 echo $version_pretty, GIT revision $REVTAG, generated `date` >$RELEASEDIR/etc/version
245 rm -rf $RELEASEDIR/tmp/*
247 if [ $MINIMAL -ne 0 ]
248 then
249 if [ "$MAKEMAP" -ne 0 ]
250 then
251 echo " * Copying symbol map to ${IMG}-symbols.txt"
252 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
253 $ZIP -f ${IMG}-symbols.txt
256 echo " * Removing files to create minimal image"
257 rm -rf $RELEASEDIR/usr/man/man*/* \
258 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
259 mkdir -p $RELEASEDIR/usr/src/releasetools
262 if [ $EXTRAS_INSTALL -ne 0 ] ; then
263 echo " * Copying files from $EXTRAS_PATH"
264 cp -Rv $EXTRAS_PATH/* $RELEASEDIR
267 # If we are making a jail, all is done!
268 if [ $JAILMODE = 1 ]
269 then echo "Created new minix install in $RELEASEDIR."
270 echo "Enter it by typing: "
271 echo "# chroot $RELEASEDIR /bin/sh"
272 exit 0
275 ##########################################################################
276 echo " * Counting files"
277 ##########################################################################
278 extrakb=`du -ks $RELEASEDIR/usr/install | awk '{ print $1 }'`
279 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
280 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
282 ##########################################################################
283 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
284 ##########################################################################
285 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
286 ROOTBLOCKS=$blocks
287 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
288 mount $TMPDISKROOT $RELEASEMNTDIR || exit
290 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
291 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
292 USRBLOCKS=$blocks
293 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
294 mkdir -m 755 $RELEASEMNTDIR/usr
295 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
297 ##########################################################################
298 echo " * Copying files from staging to image"
299 ##########################################################################
300 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
301 expr `df -kP $TMPDISKUSR | tail -1 | awk '{ print $3 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
303 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
304 umount $TMPDISKUSR || exit
306 echo " * Making image bootable"
307 cd_root_changes
309 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
310 umount $TMPDISKROOT || exit
311 rm -r $RELEASEMNTDIR
313 ##########################################################################
314 echo " * Generating image files"
315 ##########################################################################
316 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
317 cp release/cd/* $CDFILES || true
318 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
320 boottype=-n
321 bootimage=$IMAGE
323 cp $RELEASEDIR/usr/mdec/boot_monitor $CDFILES/boot
324 cp -rf $RELEASEDIR/boot/minix_latest/* $CDFILES/
325 gzip -d $CDFILES/*gz
326 writeisofs -s0x0 -l MINIX -B $bootimage $boottype $CDFILES $IMG || exit 1
328 echo "Appending Minix root and usr filesystem"
329 # Pad ISO out to cylinder boundary
330 isobytes=`stat -f %z $IMG`
331 isosects=`expr $isobytes / 512`
332 isopad=`expr $secs - '(' $isosects % $secs ')'`
333 dd if=/dev/zero count=$isopad >>$IMG
334 # number of sectors
335 isosects=`expr $isosects + $isopad`
336 ( cat $IMG $ROOTIMAGE ;
337 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
338 mv m $IMG
339 # Make CD partition table
340 installboot_nbsd -m $IMG /usr/mdec/mbr
341 # Make sure there is no hole..! Otherwise the ISO format is
342 # unreadable.
343 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
345 # Clean up: RELEASEDIR no longer needed
346 rm -r $RELEASEDIR
348 echo "${ZIP}ping $IMG"
349 $ZIP -f $IMG
351 if [ "$FILENAMEOUT" ]
352 then echo "$IMG" >$FILENAMEOUT
355 ##########################################################################
356 echo " * Freeing up memory used by ramdisks"
357 ##########################################################################
358 ramdisk 1 $TMPDISKROOT
359 ramdisk 1 $TMPDISKUSR