retire nonsymbolic rootdev, dev2name
[minix.git] / releasetools / release.sh
blobcbe1fcbb26781979613314cb613b593719a72cd4
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/rm /bin/date /bin/ls $RELEASEDIR/bin
202 cp -rp /usr/bin/make /usr/bin/yacc /usr/bin/lex /usr/bin/install /usr/bin/m4 \
203 /usr/bin/grep /usr/bin/egrep /usr/bin/awk /usr/bin/sed $RELEASEDIR/usr/bin
205 # For dynamically linked binaries: put interpreter there the
206 # system's current crop of shared libraries so they'll run;
207 # once they're rebuilt they can be thrown out in favour of the
208 # new ones like $XBIN
209 cp -p /libexec/ld.elf_so $RELEASEDIR/libexec/
210 cp -p /lib/*.so* /usr/lib/*.so* $RELEASEDIR/$XLIB/
212 CONFIGHEADER=$RELEASEDIR/usr/src/include/minix/sys_config.h
214 copy_local_packages
216 if [ "$COPY" -ne 1 ]
217 then
218 echo "Retrieving latest minix repo from $REPO branch $GITBRANCH."
219 srcdir=$RELEASEDIR/usr/src
220 git clone -b $GITBRANCH $REPO $srcdir
221 if [ "$REVTAG" ]
222 then echo "Doing checkout of $REVTAG."
223 (cd $srcdir && git checkout $REVTAG )
224 else REVTAG=`(cd $srcdir && git rev-parse --short HEAD)`
225 echo "Retrieved repository head in $srcdir is $REVTAG."
227 if [ $MINIMAL -ne 0 ]
228 then rm -r $srcdir/.git
230 echo "
231 /* Added by release script */
232 #ifndef _VCS_REVISION
233 #define _VCS_REVISION \"$REVTAG\"
234 #endif" >>$CONFIGHEADER
235 DATE=`date +%Y%m%d`
236 # output image name
237 if [ "$USB" -ne 0 ]; then
238 IMG=${IMG_BASE}_${DATE}_${REVTAG}.img
239 else
240 IMG=${IMG_BASE}_${DATE}_${REVTAG}.iso
242 else
243 echo "Copying contents from current src dir."
244 ( cd .. && make depend && make clean )
245 srcdir=/usr/$SRC
246 ( cd $srcdir && tar --exclude .svn -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
247 REVTAG=copy
248 REVISION=unknown
249 IMG=${IMG_BASE}_copy.iso
252 # Make sure the CD knows it's a CD, unless it's not
253 if [ "$USB" -eq 0 ]
254 then date >$RELEASEDIR/CD
256 echo " * Bootstrap /usr/share/mk files"
257 # Need /usr/share/mk in the new system to invoke make. Real ownerships
258 # and permissions will be set by its own src/share/mk/Makefile.
259 mkdir -p $RELEASEDIR/usr/share/mk
260 chmod 755 $RELEASEDIR/usr/share/mk
261 cp $RELEASEDIR/usr/src/share/mk/* $RELEASEDIR/usr/share/mk/
262 chown -R root $RELEASEDIR/usr/share/mk
263 rm -f $RELEASEDIR/usr/$SRC/releasetools/revision
264 cp chrootmake.sh $RELEASEDIR/usr/$SRC/releasetools/chrootmake.sh
265 mkdir -p $RELEASEDIR/etc
266 cp $RELEASEDIR/usr/src/etc/group $RELEASEDIR/etc
268 echo " * Make hierarchy"
269 sh -c "$LD_LIB chroot $RELEASEDIR sh -c \"$BUILDENV sh -x /usr/$SRC/releasetools/chrootmake.sh etcfiles\"" || exit 1
271 for p in $PREINSTALLED_PACKAGES
272 do echo " * Pre-installing: $p from $PKG_ADD_URL"
273 $PKG_ADD -f -P $RELEASEDIR $PKG_ADD_URL/$p
274 done
276 if [ "$CUSTOM_PACKAGES" ]
277 then echo $PKG_ADD_URL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
280 echo " * Resetting timestamps"
281 find $RELEASEDIR | xargs touch
282 echo " * Chroot build"
283 sh -c "$LD_LIB MAKEMAP=$MAKEMAP chroot $RELEASEDIR sh -c \"$BUILDENV sh -x /usr/$SRC/releasetools/chrootmake.sh\"" || exit 1
284 echo " * Chroot build done"
285 echo " * Removing bootstrap files"
286 rm -rf $RELEASEDIR/$XBIN
287 rm -rf $RELEASEDIR/$XLIB
288 # The build process leaves some file in $SRC as bin.
289 chown -R root $RELEASEDIR/usr/src*
290 cp issue.install $RELEASEDIR/etc/issue
292 echo $version_pretty, SVN revision $REVISION, generated `date` >$RELEASEDIR/etc/version
293 rm -rf $RELEASEDIR/tmp/*
295 if [ $MINIMAL -ne 0 ]
296 then
297 if [ "$MAKEMAP" -ne 0 ]
298 then
299 echo " * Copying symbol map to ${IMG}-symbols.txt"
300 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
301 $ZIP -f ${IMG}-symbols.txt
304 echo " * Removing files to create minimal image"
305 rm -rf $RELEASEDIR/usr/man/man*/* \
306 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
307 mkdir -p $RELEASEDIR/usr/src/releasetools
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 -k $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