release fixes
[minix3.git] / tools / release.sh
blob5218833704227fe6e6a1ed66ed906bc4324713ef
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 XBIN=usr/xbin
12 XLIB=xlib
13 SRC=src
14 REPO=git://git.minix3.org/minix
15 GITBRANCH=master
17 LD_LIB="LD_LIBRARY_PATH=/lib:/usr/lib:/$XLIB"
18 BUILDPATH="PATH=/$XBIN:/usr/pkg/bin"
19 BUILDENV="$BUILDPATH $LD_LIB"
21 # List of packages included on installation media
22 PACKAGELIST=packages.install
23 secs=`expr 32 '*' 64`
24 export SHELL=/bin/sh
26 PKG_ADD=/usr/pkg/sbin/pkg_add
27 PKG_INFO=/usr/pkg/sbin/pkg_info
29 if [ ! -x $PKG_ADD ]
30 then echo Please install pkg_install from pkgsrc.
31 exit 1
34 # Packages we have to pre-install, and url to use
35 PACKAGEURL=ftp://ftp.minix3.org/pub/minix/packages/$version_pretty/`uname -m`/All/
36 PREINSTALLED_PACKAGES="
37 pkgin
38 pkg_install
39 bmake
40 binutils
41 clang
43 # pkg_tarup
45 PKG_ADD_URL=$PACKAGEURL
47 RELEASERC=$HOME/.releaserc
49 if [ -f $RELEASERC ]
50 then . $RELEASERC
53 set -- $* $RELOPTS
55 # SVN trunk repo
56 TRUNK=https://gforge.cs.vu.nl/svn/minix/trunk
58 RELEASEDIR=/usr/r-staging
59 RELEASEMNTDIR=/usr/r
60 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
62 IMAGE=/usr/mdec/bootxx_cd9660
63 ROOTIMAGE=rootimage
64 CDFILES=/usr/tmp/cdreleasefiles
65 sh tell_config OS_RELEASE . OS_VERSION >/tmp/rel.$$
66 IMG_BASE=minix${version}_ide
67 BS=4096
69 HDEMU=0
70 COPY=0
71 JAILMODE=0
72 SVNREV=""
73 REVTAG=""
74 PACKAGES=1
75 MINIMAL=0
76 MAKEMAP=0
77 EXTRAS_INSTALL=0
78 EXTRAS_PATH=
80 # Do we have git?
81 if git --version >/dev/null
82 then if [ -d ../.git ]
83 then LOCAL_REVTAG="`git describe --always`"
84 GITMODE=1
88 FILENAMEOUT=""
90 while getopts "b:j:ls:pmMchu?r:f:L:e:" c
92 case "$c" in
93 \?)
94 echo "Usage: $0 [-l] [-p] [-c] [-h] [-m] [-M] [-r <tag>] [-u] [-f <filename>] [-s <username>] -j<jaildir> [-L <packageurl>] [-e <extras-path>]" >&2
95 exit 1
98 GITBRANCH=$OPTARG
101 echo " * Making HD image"
102 IMG_BASE=minix${version}_bios
103 HDEMU=1
106 echo " * Copying, not SVN"
107 COPY=1
110 PACKAGES=0
113 SVNREV=-r$OPTARG
116 RELEASEDIR=$OPTARG
117 JAILMODE=1
120 echo " * Making live USB-stick image"
121 IMG_BASE=minix${version}_usb
122 HDEMU=1
123 USB=1
126 FILENAMEOUT="$OPTARG"
128 s) USERNAME="--username=$OPTARG"
130 m) MINIMAL=1
131 PACKAGES=0
133 M) MAKEMAP=1
135 l) PKG_ADD_URL=file://$PACKAGEDIR/All
137 L) PKG_ADD_URL="$OPTARG"
138 CUSTOM_PACKAGES=1
140 e) EXTRAS_INSTALL=1
141 EXTRAS_PATH="$OPTARG"
143 esac
144 done
146 if [ $GITMODE -ne 1 -a $COPY -ne 1 ]
147 then echo "Need git to retrieve latest minix! Copying src instead!"
148 COPY=1
151 if [ ! "$ZIP" ]
152 then ZIP=bzip2
155 if [ $PACKAGES -ne 0 ]
156 then mkdir -p $PACKAGEDIR/All || true
157 retrieve $PACKAGEDIR/All $PACKAGELIST packages/`uname -p`/$VERSION_PRETTY
160 TMPDISKUSR=/dev/ram0
161 TMPDISKROOT=/dev/ram1
163 if [ ! -b $TMPDISKUSR -o ! $TMPDISKROOT ]
164 then echo "$TMPDISKUSR or $TMPDISKROOT is not a block device.."
165 exit 1
168 if [ $TMPDISKUSR = $TMPDISKROOT ]
169 then
170 echo "Temporary devices can't be equal."
171 exit
174 if [ $JAILMODE = 0 ]
175 then echo " * Cleanup old files"
176 umount $TMPDISKUSR || true
177 umount $TMPDISKROOT || true
178 umount $RELEASEMNTDIR/usr || true
179 umount $RELEASEMNTDIR || true
182 rm -rf $RELEASEDIR $RELEASEMNTDIR $IMG $ROOTIMAGE $CDFILES image* || true
183 mkdir -p $CDFILES || exit
184 mkdir -p $RELEASEDIR $RELEASEMNTDIR
185 mkdir -m 755 $RELEASEDIR/usr
186 mkdir -m 1777 $RELEASEDIR/tmp
188 mkdir -p $RELEASEDIR/tmp
189 mkdir -p $RELEASEDIR/usr/tmp
190 mkdir -p $RELEASEDIR/$XBIN
191 mkdir -p $RELEASEDIR/$XLIB
192 mkdir -p $RELEASEDIR/libexec
193 mkdir -p $RELEASEDIR/usr/bin
194 mkdir -p $RELEASEDIR/bin
195 mkdir -p $RELEASEPACKAGE
197 echo " * Transfering bootstrap dirs to $RELEASEDIR"
199 # Actual binaries
200 cp -p /bin/* /usr/bin/* /usr/sbin/* /sbin/* $RELEASEDIR/$XBIN
201 cp -rp /bin/cat /bin/sh /bin/echo /bin/install /bin/rm \
202 /bin/date /bin/ls $RELEASEDIR/bin
203 cp -rp /usr/bin/make /usr/bin/yacc /usr/bin/lex \
204 /usr/bin/grep /usr/bin/egrep /usr/bin/awk /usr/bin/sed $RELEASEDIR/usr/bin
206 # For dynamically linked binaries: put interpreter there the
207 # system's current crop of shared libraries so they'll run;
208 # once they're rebuilt they can be thrown out in favour of the
209 # new ones like $XBIN
210 cp -p /libexec/ld.elf_so $RELEASEDIR/libexec/
211 cp -p /lib/*.so* /usr/lib/*.so* $RELEASEDIR/$XLIB/
213 CONFIGHEADER=$RELEASEDIR/usr/src/include/minix/sys_config.h
215 copy_local_packages
217 if [ "$COPY" -ne 1 ]
218 then
219 echo "Retrieving latest minix repo from $REPO branch $GITBRANCH."
220 srcdir=$RELEASEDIR/usr/src
221 git clone -b $GITBRANCH $REPO $srcdir
222 if [ "$REVTAG" ]
223 then echo "Doing checkout of $REVTAG."
224 (cd $srcdir && git checkout $REVTAG )
225 else REVTAG=`(cd $srcdir && git rev-parse --short HEAD)`
226 echo "Retrieved repository head in $srcdir is $REVTAG."
228 if [ $MINIMAL -ne 0 ]
229 then rm -r $srcdir/.git
231 echo "
232 /* Added by release script */
233 #ifndef _VCS_REVISION
234 #define _VCS_REVISION \"$REVTAG\"
235 #endif" >>$CONFIGHEADER
236 DATE=`date +%Y%m%d`
237 # output image name
238 if [ "$USB" -ne 0 ]; then
239 IMG=${IMG_BASE}_${DATE}_${REVTAG}.img
240 else
241 IMG=${IMG_BASE}_${DATE}_${REVTAG}.iso
243 else
244 echo "Copying contents from current src dir."
245 ( cd .. && make depend && make clean )
246 srcdir=/usr/$SRC
247 ( cd $srcdir && tar --exclude .svn -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
248 REVTAG=copy
249 REVISION=unknown
250 IMG=${IMG_BASE}_copy.iso
253 # Make sure the CD knows it's a CD, unless it's not
254 if [ "$USB" -eq 0 ]
255 then date >$RELEASEDIR/CD
257 echo " * Bootstrap /usr/share/mk files"
258 # Need /usr/share/mk in the new system to invoke make. Real ownerships
259 # and permissions will be set by its own src/share/mk/Makefile.
260 mkdir -p $RELEASEDIR/usr/share/mk
261 chmod 755 $RELEASEDIR/usr/share/mk
262 cp $RELEASEDIR/usr/src/share/mk/* $RELEASEDIR/usr/share/mk/
263 chown -R root $RELEASEDIR/usr/share/mk
264 rm -f $RELEASEDIR/usr/$SRC/tools/revision
265 cp chrootmake.sh $RELEASEDIR/usr/$SRC/tools/chrootmake.sh
267 echo " * Make hierarchy"
268 sh -c "$LD_LIB chroot $RELEASEDIR sh -c \"$BUILDENV sh -x /usr/$SRC/tools/chrootmake.sh etcfiles\"" || exit 1
270 for p in $PREINSTALLED_PACKAGES
271 do echo " * Pre-installing: $p from $PKG_ADD_URL"
272 $PKG_ADD -f -P $RELEASEDIR $PKG_ADD_URL/$p
273 done
275 if [ "$CUSTOM_PACKAGES" ]
276 then echo $PKG_ADD_URL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
279 echo " * Resetting timestamps"
280 find $RELEASEDIR | xargs touch
281 echo " * Chroot build"
282 sh -c "$LD_LIB MAKEMAP=$MAKEMAP chroot $RELEASEDIR sh -c \"$BUILDENV sh -x /usr/$SRC/tools/chrootmake.sh\"" || exit 1
283 echo " * Chroot build done"
284 echo " * Removing bootstrap files"
285 rm -rf $RELEASEDIR/$XBIN
286 rm -rf $RELEASEDIR/$XLIB
287 # The build process leaves some file in $SRC as bin.
288 chown -R root $RELEASEDIR/usr/src*
289 cp issue.install $RELEASEDIR/etc/issue
291 echo $version_pretty, SVN revision $REVISION, generated `date` >$RELEASEDIR/etc/version
292 rm -rf $RELEASEDIR/tmp/*
294 if [ $MINIMAL -ne 0 ]
295 then
296 if [ "$MAKEMAP" -ne 0 ]
297 then
298 echo " * Copying symbol map to ${IMG}-symbols.txt"
299 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
300 $ZIP -f ${IMG}-symbols.txt
303 echo " * Removing files to create minimal image"
304 rm -rf $RELEASEDIR/boot/image/* $RELEASEDIR/usr/man/man*/* \
305 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
306 mkdir -p $RELEASEDIR/usr/src/tools
307 ln $RELEASEDIR/boot/image_big $RELEASEDIR/boot/image/$version
310 if [ $EXTRAS_INSTALL -ne 0 ] ; then
311 echo " * Copying files from $EXTRAS_PATH"
312 cp -Rv $EXTRAS_PATH/* $RELEASEDIR
315 # If we are making a jail, all is done!
316 if [ $JAILMODE = 1 ]
317 then echo "Created new minix install in $RELEASEDIR."
318 echo "Enter it by typing: "
319 echo "# chroot $RELEASEDIR /bin/sh"
320 exit 0
323 echo " * Counting files"
324 extrakb=`du -ks $RELEASEDIR/usr/install | awk '{ print $1 }'`
325 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
326 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
328 fstab_marker="# Poor man's File System Table."
329 echo " * Writing fstab"
330 if [ "$USB" -ne 0 ]
331 then
332 echo \
333 "$fstab_marker
334 root=/dev/c0d7p0s0
335 usr=/dev/c0d7p0s2
336 " > $RELEASEDIR/etc/fstab
337 elif [ "$HDEMU" -ne 0 ]
338 then
339 echo \
340 "$fstab_marker
341 root=/dev/c0d7p0s0
342 usr=/dev/c0d7p0s2
343 usr_roflag=\"-r\"" > $RELEASEDIR/etc/fstab
346 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
347 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
348 ROOTBLOCKS=$blocks
349 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
350 mount $TMPDISKROOT $RELEASEMNTDIR || exit
352 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
353 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
354 USRBLOCKS=$blocks
355 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
356 mkdir -m 755 $RELEASEMNTDIR/usr
357 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
359 echo " * Copying files from staging to image"
360 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
361 expr `df $TMPDISKUSR | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
363 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
364 umount $TMPDISKUSR || exit
366 echo " * Making image bootable"
367 if [ "$USB" -ne 0 ]
368 then
369 usb_root_changes
370 elif [ "$HDEMU" -ne 0 ]
371 then
372 hdemu_root_changes
373 else
374 cd_root_changes
377 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
378 umount $TMPDISKROOT || exit
379 rm -r $RELEASEMNTDIR
381 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
382 cp release/cd/* $CDFILES || true
383 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
385 boottype=-n
386 bootimage=$IMAGE
387 if [ "$HDEMU" -ne 0 ]; then
388 make_hdimage
389 boottype='-h'
390 bootimage=hdimage
393 if [ "$USB" -ne 0 ]; then
394 mv $bootimage $IMG
395 else
396 cp $RELEASEDIR/usr/mdec/boot_monitor $CDFILES/boot
397 cp -rf $RELEASEDIR/boot/minix_latest/* $CDFILES/
398 gzip -d $CDFILES/*gz
399 writeisofs -s0x0 -l MINIX -B $bootimage $boottype $CDFILES $IMG || exit 1
401 if [ "$HDEMU" -eq 0 ]
402 then
403 echo "Appending Minix root and usr filesystem"
404 # Pad ISO out to cylinder boundary
405 isobytes=`stat -f %z $IMG`
406 isosects=`expr $isobytes / 512`
407 isopad=`expr $secs - '(' $isosects % $secs ')'`
408 dd if=/dev/zero count=$isopad >>$IMG
409 # number of sectors
410 isosects=`expr $isosects + $isopad`
411 ( cat $IMG $ROOTIMAGE ;
412 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
413 mv m $IMG
414 # Make CD partition table
415 installboot_nbsd -m $IMG /usr/mdec/mbr
416 # Make sure there is no hole..! Otherwise the ISO format is
417 # unreadable.
418 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
422 # Clean up: RELEASEDIR no longer needed
423 rm -r $RELEASEDIR
425 echo "${ZIP}ping $IMG"
426 $ZIP -f $IMG
428 if [ "$FILENAMEOUT" ]
429 then echo "$IMG" >$FILENAMEOUT
432 echo " * Freeing up memory used by ramdisks"
433 ramdisk 1 $TMPDISKROOT
434 ramdisk 1 $TMPDISKUSR