release script fixes
[minix3.git] / releasetools / release.sh
blobe394e7f25a65b8466e5c0f261f20c6228c70bb5c
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
36 PKG_ADD_URL=$PACKAGEURL
38 RELEASERC=$HOME/.releaserc
40 if [ -f $RELEASERC ]
41 then . $RELEASERC
44 set -- $* $RELOPTS
46 export RELEASEDIR=/usr/r-staging
47 RELEASEMNTDIR=/usr/r
49 IMAGE=/usr/mdec/bootxx_cd9660
50 ROOTIMAGE=rootimage
51 CDFILES=/usr/tmp/cdreleasefiles
52 IMG_BASE=minix${version}_ide
53 BS=4096
55 COPY=0
56 JAILMODE=0
57 REVTAG=""
58 PACKAGES=1
59 MINIMAL=0
60 MAKEMAP=0
61 EXTRAS_INSTALL=0
62 EXTRAS_PATH=
64 # Do we have git?
65 if git --version >/dev/null
66 then if [ -d ../.git ]
67 then LOCAL_REVTAG="`git describe --always`"
68 GITMODE=1
72 FILENAMEOUT=""
74 while getopts "b:j:lpmMch?f:L:e:" c
76 case "$c" in
77 \?)
78 echo "Usage: $0 [-l] [-p] [-c] [-m] [-M] [-f <filename>] -j<jaildir> [-L <packageurl>] [-e <extras-path>]" >&2
79 exit 1
82 GITBRANCH=$OPTARG
85 echo " * Copying, not using GIT"
86 COPY=1
89 PACKAGES=0
92 RELEASEDIR=$OPTARG
93 JAILMODE=1
96 FILENAMEOUT="$OPTARG"
98 m) MINIMAL=1
99 PACKAGES=0
101 M) MAKEMAP=1
103 l) PKG_ADD_URL=file://$PACKAGEDIR/All
105 L) PKG_ADD_URL="$OPTARG"
106 CUSTOM_PACKAGES=1
108 e) EXTRAS_INSTALL=1
109 EXTRAS_PATH="$OPTARG"
111 esac
112 done
114 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
116 if [ $GITMODE -ne 1 -a $COPY -ne 1 ]
117 then echo "Need git to retrieve latest minix! Copying src instead!"
118 COPY=1
121 if [ ! "$ZIP" ]
122 then ZIP=bzip2
125 if [ $PACKAGES -ne 0 ]
126 then mkdir -p $PACKAGEDIR/All || true
127 retrieve $PACKAGEDIR/All $PACKAGELIST packages/`uname -p`/$VERSION_PRETTY
130 TMPDISKUSR=/dev/ram0
131 TMPDISKROOT=/dev/ram1
133 if [ ! -b $TMPDISKUSR -o ! $TMPDISKROOT ]
134 then echo "$TMPDISKUSR or $TMPDISKROOT is not a block device.."
135 exit 1
138 if [ $TMPDISKUSR = $TMPDISKROOT ]
139 then
140 echo "Temporary devices can't be equal."
141 exit
144 if [ $JAILMODE = 0 ]
145 then echo " * Cleanup old files"
146 umount $TMPDISKUSR || true
147 umount $TMPDISKROOT || true
148 umount $RELEASEMNTDIR/usr || true
149 umount $RELEASEMNTDIR || true
152 rm -rf $RELEASEDIR $RELEASEMNTDIR $IMG $ROOTIMAGE $CDFILES image* || true
153 mkdir -p $CDFILES || exit
154 mkdir -p $RELEASEDIR $RELEASEMNTDIR
155 mkdir -p $RELEASEPACKAGE
157 ##########################################################################
158 echo " * Bootstrapping filesystem in $RELEASEDIR"
159 ##########################################################################
160 CONFIGHEADER=$RELEASEDIR/usr/src/include/minix/sys_config.h
162 copy_local_packages
164 if [ "$COPY" -ne 1 ]
165 then
166 echo "Retrieving latest minix repo from $REPO branch $GITBRANCH."
167 srcdir=$RELEASEDIR/usr/src
168 git clone -b $GITBRANCH $REPO $srcdir
169 echo "Triggering fetch scripts"
170 ( cd $srcdir && sh ./gnu/dist/fetch.sh )
171 ( cd $srcdir && sh ./external/gpl3/binutils/fetch.sh )
172 if [ "$REVTAG" ]
173 then echo "Doing checkout of $REVTAG."
174 (cd $srcdir && git checkout $REVTAG )
175 else REVTAG=`(cd $srcdir && git rev-parse --short HEAD)`
176 echo "Retrieved repository head in $srcdir is $REVTAG."
178 if [ $MINIMAL -ne 0 ]
179 then rm -r $srcdir/.git
181 echo "
182 /* Added by release script */
183 #ifndef _VCS_REVISION
184 #define _VCS_REVISION \"$REVTAG\"
185 #endif" >>$CONFIGHEADER
186 DATE=`date +%Y%m%d`
187 # output image name
188 IMG=${IMG_BASE}_${DATE}_${REVTAG}.iso
189 else
190 echo "First cleaning current sourcedir.."
191 ( cd .. && make cleandir >/dev/null )
192 echo "Copying contents from current src dir."
193 srcdir=/usr/$SRC
194 ( cd $srcdir && tar --exclude .git -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
195 echo "Copying done."
196 REVTAG=copy
197 IMG=${IMG_BASE}_copy.iso
200 # Make sure the CD knows it's a CD, unless it's not
201 date >$RELEASEDIR/CD
203 rm -f $RELEASEDIR/usr/$SRC/releasetools/revision
205 for p in $PREINSTALLED_PACKAGES
206 do echo " * Pre-installing: $p from $PKG_ADD_URL"
207 $PKG_ADD -f -P $RELEASEDIR $PKG_ADD_URL/$p
208 done
210 if [ "$CUSTOM_PACKAGES" ]
211 then echo $PKG_ADD_URL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
214 echo " * Resetting timestamps"
215 find $RELEASEDIR | xargs touch
217 ##########################################################################
218 echo " * Build"
219 ##########################################################################
221 cd $RELEASEDIR/usr/src
222 make build MKLIBCXX=yes DESTDIR=$RELEASEDIR SLOPPY_FLIST=yes $BUILDOPTIONS
223 make -C releasetools do-hdboot DESTDIR=$RELEASEDIR MKINSTALLBOOT=yes
224 cp $RELEASEDIR/usr/mdec/boot_monitor $RELEASEDIR
225 cp $RELEASEDIR/boot/minix_latest/* $RELEASEDIR/boot/minix_default/
227 if [ $MAKEMAP -ne 0 ]; then
228 find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
230 make cleandir
232 cd -
234 echo " * build done"
236 ##########################################################################
237 echo " * Removing bootstrap files"
238 ##########################################################################
239 # The build process leaves some file in $SRC as bin.
240 chown -R root $RELEASEDIR/usr/src*
241 cp issue.install $RELEASEDIR/etc/issue
243 echo $version_pretty, GIT revision $REVTAG, generated `date` >$RELEASEDIR/etc/version
244 rm -rf $RELEASEDIR/tmp/*
246 if [ $MINIMAL -ne 0 ]
247 then
248 if [ "$MAKEMAP" -ne 0 ]
249 then
250 echo " * Copying symbol map to ${IMG}-symbols.txt"
251 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
252 $ZIP -f ${IMG}-symbols.txt
255 echo " * Removing files to create minimal image"
256 rm -rf $RELEASEDIR/usr/man/man*/* \
257 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
258 mkdir -p $RELEASEDIR/usr/src/releasetools
261 if [ $EXTRAS_INSTALL -ne 0 ] ; then
262 echo " * Copying files from $EXTRAS_PATH"
263 cp -Rv $EXTRAS_PATH/* $RELEASEDIR
266 echo " * Removing sources"
268 rm -rf $RELEASEDIR/usr/src # No space for /usr/src
270 # If we are making a jail, all is done!
271 if [ $JAILMODE = 1 ]
272 then echo "Created new minix install in $RELEASEDIR."
273 echo "Enter it by typing: "
274 echo "# chroot $RELEASEDIR /bin/sh"
275 exit 0
278 ##########################################################################
279 echo " * Counting files"
280 ##########################################################################
281 extrakb=`du -ks $RELEASEDIR/usr/install | awk '{ print $1 }'`
282 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
283 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
285 ##########################################################################
286 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
287 ##########################################################################
288 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
289 ROOTBLOCKS=$blocks
290 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
291 mount $TMPDISKROOT $RELEASEMNTDIR || exit
293 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
294 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
295 USRBLOCKS=$blocks
296 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
297 mkdir -m 755 $RELEASEMNTDIR/usr
298 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
300 ##########################################################################
301 echo " * Copying files from staging to image"
302 ##########################################################################
303 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
304 expr `df -kP $TMPDISKUSR | tail -1 | awk '{ print $3 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
306 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
307 umount $TMPDISKUSR || exit
309 echo " * Making image bootable"
310 cd_root_changes
312 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
313 umount $TMPDISKROOT || exit
314 rm -r $RELEASEMNTDIR
316 ##########################################################################
317 echo " * Generating image files"
318 ##########################################################################
319 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
320 cp release/cd/* $CDFILES || true
321 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
323 boottype=-n
324 bootimage=$IMAGE
326 cp $RELEASEDIR/usr/mdec/boot_monitor $CDFILES/boot
327 cp -rf $RELEASEDIR/boot/minix_latest/* $CDFILES/
328 gzip -d $CDFILES/*gz
329 writeisofs -s0x0 -l MINIX -B $bootimage $boottype $CDFILES $IMG || exit 1
331 echo "Appending Minix root and usr filesystem"
332 # Pad ISO out to cylinder boundary
333 isobytes=`stat -f %z $IMG`
334 isosects=`expr $isobytes / 512`
335 isopad=`expr $secs - '(' $isosects % $secs ')'`
336 dd if=/dev/zero count=$isopad >>$IMG
337 # number of sectors
338 isosects=`expr $isosects + $isopad`
339 ( cat $IMG $ROOTIMAGE ;
340 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
341 mv m $IMG
342 # Make CD partition table
343 installboot_nbsd -m $IMG /usr/mdec/mbr
344 # Make sure there is no hole..! Otherwise the ISO format is
345 # unreadable.
346 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
348 # Clean up: RELEASEDIR no longer needed
349 rm -r $RELEASEDIR
351 echo "${ZIP}ping $IMG"
352 $ZIP -f $IMG
354 if [ "$FILENAMEOUT" ]
355 then echo "$IMG" >$FILENAMEOUT
358 ##########################################################################
359 echo " * Freeing up memory used by ramdisks"
360 ##########################################################################
361 ramdisk 1 $TMPDISKROOT
362 ramdisk 1 $TMPDISKUSR