Import NetBSD's passwd.conf
[minix3.git] / releasetools / release.sh
blob9b3e4b59d16960b858933bb68dab8f77224c6945
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 # Packages we have to pre-install, and url to use
17 : ${PACKAGEURL="http://www.minix3.org/pkgsrc/packages/$version_pretty/`uname -m`/All/"}
18 : ${PREINSTALLED_PACKAGES:="pkg_install pkgin"}
20 # List of packages included on installation media
21 PACKAGELIST=packages.install
22 secs=`expr 32 '*' 64`
23 export SHELL=/bin/sh
25 PKG_ADD=/usr/pkg/sbin/pkg_add
26 PKG_INFO=/usr/pkg/sbin/pkg_info
28 if [ ! -x $PKG_ADD ]
29 then echo Please install pkg_install from pkgsrc.
30 exit 1
33 RELEASERC=$HOME/.releaserc
35 if [ -f $RELEASERC ]
36 then . $RELEASERC
39 set -- $* $RELOPTS
41 export RELEASEDIR=/usr/r-staging
42 RELEASEMNTDIR=/usr/r
44 IMAGE=/usr/mdec/bootxx_cd9660
45 ROOTIMAGE=rootimage
46 CDFILES=/usr/tmp/cdreleasefiles
47 IMG_BASE=minix${version}_ide
48 BS=4096
50 COPY=0
51 JAILMODE=0
52 REVTAG=""
53 PACKAGES=1
54 MINIMAL=0
55 MAKEMAP=0
56 EXTRAS_INSTALL=0
57 EXTRAS_PATH=
59 # Do we have git?
60 if git --version >/dev/null
61 then if [ -d ../.git ]
62 then LOCAL_REVTAG="`git describe --always`"
63 GITMODE=1
67 FILENAMEOUT=""
69 while getopts "b:j:lpmMch?f:L:e:" c
71 case "$c" in
72 \?)
73 echo "Usage: $0 [-l] [-p] [-c] [-m] [-M] [-f <filename>] -j<jaildir> [-L <packageurl>] [-e <extras-path>]" >&2
74 exit 1
77 GITBRANCH=$OPTARG
80 echo " * Copying, not using GIT"
81 COPY=1
84 PACKAGES=0
87 RELEASEDIR=$OPTARG
88 JAILMODE=1
91 FILENAMEOUT="$OPTARG"
93 m) MINIMAL=1
94 PACKAGES=0
96 M) MAKEMAP=1
98 l) PACKAGEURL=file://$PACKAGEDIR/All
100 L) PACKAGEURL="$OPTARG"
101 CUSTOM_PACKAGES=1
103 e) EXTRAS_INSTALL=1
104 EXTRAS_PATH="$OPTARG"
106 esac
107 done
109 RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
111 if [ $GITMODE -ne 1 -a $COPY -ne 1 ]
112 then echo "Need git to retrieve latest minix! Copying src instead!"
113 COPY=1
116 if [ ! "$ZIP" ]
117 then ZIP=bzip2
120 if [ $PACKAGES -ne 0 ]
121 then mkdir -p $PACKAGEDIR/All || true
122 retrieve $PACKAGEDIR/All $PACKAGELIST packages/`uname -p`/$VERSION_PRETTY
125 TMPDISKUSR=/dev/ram0
126 TMPDISKROOT=/dev/ram1
128 if [ ! -b $TMPDISKUSR -o ! $TMPDISKROOT ]
129 then echo "$TMPDISKUSR or $TMPDISKROOT is not a block device.."
130 exit 1
133 if [ $TMPDISKUSR = $TMPDISKROOT ]
134 then
135 echo "Temporary devices can't be equal."
136 exit
139 if [ $JAILMODE = 0 ]
140 then echo " * Cleanup old files"
141 umount $TMPDISKUSR || true
142 umount $TMPDISKROOT || true
143 umount $RELEASEMNTDIR/usr || true
144 umount $RELEASEMNTDIR || true
147 rm -rf $RELEASEDIR $RELEASEMNTDIR $IMG $ROOTIMAGE $CDFILES image* || true
148 mkdir -p $CDFILES || exit
149 mkdir -p $RELEASEDIR $RELEASEMNTDIR
150 mkdir -p $RELEASEPACKAGE
152 ##########################################################################
153 echo " * Bootstrapping filesystem in $RELEASEDIR"
154 ##########################################################################
155 CONFIGHEADER=$RELEASEDIR/usr/src/minix/include/minix/sys_config.h
157 copy_local_packages
159 if [ "$COPY" -ne 1 ]
160 then
161 echo "Retrieving latest minix repo from $REPO branch $GITBRANCH."
162 srcdir=$RELEASEDIR/usr/src
163 git clone -b $GITBRANCH $REPO $srcdir
164 echo "Triggering fetch scripts"
165 ( cd $srcdir && sh ./gnu/dist/fetch.sh )
166 ( cd $srcdir && sh ./external/gpl3/binutils/fetch.sh )
167 if [ "$REVTAG" ]
168 then echo "Doing checkout of $REVTAG."
169 (cd $srcdir && git checkout $REVTAG )
170 else REVTAG=`(cd $srcdir && git rev-parse --short HEAD)`
171 echo "Retrieved repository head in $srcdir is $REVTAG."
173 if [ $MINIMAL -ne 0 ]
174 then rm -r $srcdir/.git
176 echo "
177 /* Added by release script */
178 #ifndef _VCS_REVISION
179 #define _VCS_REVISION \"$REVTAG\"
180 #endif" >>$CONFIGHEADER
181 DATE=`date +%Y%m%d`
182 # output image name
183 IMG=${IMG_BASE}_${DATE}_${REVTAG}.iso
184 else
185 echo "First cleaning current sourcedir.."
186 ( cd .. && make cleandir >/dev/null )
187 echo "Copying contents from current src dir."
188 srcdir=/usr/$SRC
189 ( cd $srcdir && tar --exclude .git -cf - . ) | ( cd $RELEASEDIR/usr && mkdir $SRC && cd $SRC && tar xf - )
190 echo "Copying done."
191 REVTAG=copy
192 IMG=${IMG_BASE}_copy.iso
195 # Make sure the CD knows it's a CD, unless it's not
196 date >$RELEASEDIR/CD
198 rm -f $RELEASEDIR/usr/$SRC/releasetools/revision
200 for p in $PREINSTALLED_PACKAGES
201 do echo " * Pre-installing: $p from $PACKAGEURL"
202 $PKG_ADD -f -P $RELEASEDIR $PACKAGEURL/$p
203 done
205 if [ "$CUSTOM_PACKAGES" ]
206 then echo $PACKAGEURL >$RELEASEDIR/usr/pkg/etc/pkgin/repositories.conf
209 echo " * Resetting timestamps"
210 find $RELEASEDIR -print0 | xargs -n1000 -0 touch
212 ##########################################################################
213 echo " * Build"
214 ##########################################################################
216 cd $RELEASEDIR/usr/src
217 make distribution MKLIBCXX=yes DESTDIR=$RELEASEDIR SLOPPY_FLIST=yes $BUILDOPTIONS
218 make -C releasetools do-hdboot DESTDIR=$RELEASEDIR MKINSTALLBOOT=yes
219 cp $RELEASEDIR/usr/mdec/boot_monitor $RELEASEDIR
220 cp $RELEASEDIR/boot/minix_latest/* $RELEASEDIR/boot/minix_default/
222 if [ $MAKEMAP -ne 0 ]; then
223 find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
225 make cleandir
227 cd -
229 echo " * build done"
231 ##########################################################################
232 echo " * Removing bootstrap files"
233 ##########################################################################
234 # The build process leaves some file in $SRC as bin.
235 chown -R root $RELEASEDIR/usr/src*
236 cp issue.install $RELEASEDIR/etc/issue
238 echo $version_pretty, GIT revision $REVTAG, generated `date` >$RELEASEDIR/etc/version
239 rm -rf $RELEASEDIR/tmp/*
241 if [ $MINIMAL -ne 0 ]
242 then
243 if [ "$MAKEMAP" -ne 0 ]
244 then
245 echo " * Copying symbol map to ${IMG}-symbols.txt"
246 cp $RELEASEDIR/usr/src/symbols.txt ${IMG}-symbols.txt
247 $ZIP -f ${IMG}-symbols.txt
250 echo " * Removing files to create minimal image"
251 rm -rf $RELEASEDIR/usr/man/man*/* \
252 $RELEASEDIR/usr/share/zoneinfo* $RELEASEDIR/usr/src
253 mkdir -p $RELEASEDIR/usr/src/releasetools
256 if [ $EXTRAS_INSTALL -ne 0 ] ; then
257 echo " * Copying files from $EXTRAS_PATH"
258 cp -Rv $EXTRAS_PATH/* $RELEASEDIR
261 echo " * Removing sources"
263 rm -rf $RELEASEDIR/usr/src # No space for /usr/src
264 rm -f $RELEASEDIR/SETS.* # No need for those.
266 # If we are making a jail, all is done!
267 if [ $JAILMODE = 1 ]
268 then echo "Created new minix install in $RELEASEDIR."
269 echo "Enter it by typing: "
270 echo "# chroot $RELEASEDIR /bin/sh"
271 exit 0
274 ##########################################################################
275 echo " * Counting files"
276 ##########################################################################
277 extrakb=`du -ks $RELEASEDIR/usr/install | awk '{ print $1 }'`
278 find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
279 find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
281 ##########################################################################
282 echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"
283 ##########################################################################
284 fitfs $RELEASEDIR $TMPDISKROOT 64 256 "$ROOTMB"
285 ROOTBLOCKS=$blocks
286 ROOTSECTS="`expr $blocks \* \( $BS / 512 \)`"
287 mount $TMPDISKROOT $RELEASEMNTDIR || exit
289 echo " * Mounting $TMPDISKUSR as $RELEASEMNTDIR/usr"
290 fitfs $RELEASEDIR/usr $TMPDISKUSR 0 0 "$USRMB"
291 USRBLOCKS=$blocks
292 USRSECTS="`expr $blocks \* \( $BS / 512 \)`"
293 mkdir -m 755 $RELEASEMNTDIR/usr
294 mount $TMPDISKUSR $RELEASEMNTDIR/usr || exit
296 ##########################################################################
297 echo " * Copying files from staging to image"
298 ##########################################################################
299 synctree -f $RELEASEDIR $RELEASEMNTDIR > /dev/null || true
300 expr `df -kP $TMPDISKUSR | tail -1 | awk '{ print $3 }'` - $extrakb >$RELEASEMNTDIR/.usrkb
302 echo " * Unmounting $TMPDISKUSR from $RELEASEMNTDIR/usr"
303 umount $TMPDISKUSR || exit
305 echo " * Making image bootable"
306 cd_root_changes
308 echo " * Unmounting $TMPDISKROOT from $RELEASEMNTDIR"
309 umount $TMPDISKROOT || exit
310 rm -r $RELEASEMNTDIR
312 ##########################################################################
313 echo " * Generating image files"
314 ##########################################################################
315 dd if=$TMPDISKROOT of=$ROOTIMAGE bs=$BS count=$ROOTBLOCKS
316 cp release/cd/* $CDFILES || true
317 echo "This is Minix version $version_pretty prepared `date`." >$CDFILES/VERSION.TXT
319 boottype=-n
320 bootimage=$IMAGE
322 cp $RELEASEDIR/usr/mdec/boot_monitor $CDFILES/boot
323 cp -rf $RELEASEDIR/boot/minix_latest/* $CDFILES/
324 gzip -d $CDFILES/*gz
325 writeisofs -s0x0 -l MINIX -B $bootimage $boottype $CDFILES $IMG || exit 1
327 echo "Appending Minix root and usr filesystem"
328 # Pad ISO out to cylinder boundary
329 isobytes=`stat -f %z $IMG`
330 isosects=`expr $isobytes / 512`
331 isopad=`expr $secs - '(' $isosects % $secs ')'`
332 dd if=/dev/zero count=$isopad >>$IMG
333 # number of sectors
334 isosects=`expr $isosects + $isopad`
335 ( cat $IMG $ROOTIMAGE ;
336 dd if=$TMPDISKUSR bs=$BS count=$USRBLOCKS ) >m
337 mv m $IMG
338 # Make CD partition table
339 installboot_nbsd -m $IMG /usr/mdec/mbr
340 # Make sure there is no hole..! Otherwise the ISO format is
341 # unreadable.
342 partition -m $IMG 0 81:$isosects 81:$ROOTSECTS 81:$USRSECTS
344 # Clean up: RELEASEDIR no longer needed
345 rm -r $RELEASEDIR
347 if [ "$FILENAMEOUT" ]
348 then echo "$IMG" >$FILENAMEOUT
351 ##########################################################################
352 echo " * Freeing up memory used by ramdisks"
353 ##########################################################################
354 ramdisk 1 $TMPDISKROOT
355 ramdisk 1 $TMPDISKUSR