7 # Add a directory to a spec file
9 # $1 : directory to add
13 echo "./$1 type=dir uid=0 gid=0 mode=0755" >> ${WORK_DIR}/$2
17 # Add a file to a spec file
23 echo "./$1 type=file uid=0 gid=0 mode=0755 size=$(wc -c < ${ROOT_DIR}/${1})" >> ${WORK_DIR}/$2
27 # Add a symbolic link to a spec file
34 echo "./$1 type=link uid=0 gid=0 mode=0755 link=$2" >> ${WORK_DIR}/$3
42 # Create the workdir (a directory where Minix is built using sets)
43 # spec files are put in WORK_DIR, the file system created in ROOT_DIR
45 # $1 : sets to extract
51 if [ ! -e ${SETS_DIR}/${set}.tgz ]; then
52 echo "Missing ${SETS_DIR}/${set}.tgz, aborting"
53 echo "Are the release sets tarballs created?"
56 echo " * Extracting $set..."
57 (cd ${ROOT_DIR}; ${CROSS_TOOLS}/nbpax -rnz -f ${SETS_DIR}/${set}.tgz .)
62 cp ${RC} ${ROOT_DIR}/usr/etc/rc.local
65 # Build login/password files
66 ${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${ROOT_DIR} ${ROOT_DIR}/etc/master.passwd
68 # Build specifications files
69 cp ${ROOT_DIR}/etc/mtree/set* ${WORK_DIR}
70 ${ROOT_DIR}/usr/bin/MAKEDEV -s -m all >> ${WORK_DIR}/extra.dev
72 if [ ${BUNDLE_SETS} -eq 1 ]
74 echo " * Bundling sets..."
80 # Add tarball sets to the workdir (for installation CD)
84 # Add sets to the root
85 mkdir -p ${ROOT_DIR}/usr/${ARCH}/binary/sets;
86 add_dir_spec "usr/${ARCH}" extra.sets
87 add_dir_spec "usr/${ARCH}/binary" extra.sets
88 add_dir_spec "usr/${ARCH}/binary/sets" extra.sets
90 add_link_spec "${ARCH}" "usr/${ARCH}" extra.sets
92 DEST_SETS_DIR="usr/${ARCH}/binary/sets"
93 for set in ${SETS_DIR}/*.tgz; do
95 cp ${set} ${ROOT_DIR}/${DEST_SETS_DIR}
96 add_file_spec "${DEST_SETS_DIR}/$(basename ${set})" extra.sets
99 COUNT_SRC=$(echo $(basename ${set}) | sed -e "s/\(.*\)\.tgz/\set.\1/")
100 COUNT_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.count/")
101 if [ -e "${DESTDIR}/etc/mtree/${COUNT_SRC}" ]
103 wc -l < ${DESTDIR}/etc/mtree/${COUNT_SRC} > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME}
105 # Can't find mtree file, set bogus number
106 echo 1 > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME}
108 add_file_spec "${DEST_SETS_DIR}/${COUNT_NAME}" extra.sets
111 SIZE_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.size/")
112 ${CROSS_TOOLS}/nbpax -zvf ${set} . |grep -v 'bytes written in 1 secs [(]' | ${CROSS_TOOLS}/nbawk '{s+=$5} END{print s}' > ${ROOT_DIR}/${DEST_SETS_DIR}/${SIZE_NAME}
113 add_file_spec "${DEST_SETS_DIR}/${SIZE_NAME}" extra.sets
117 cp ${SETS_DIR}/MD5 ${ROOT_DIR}/${DEST_SETS_DIR}
118 add_file_spec "${DEST_SETS_DIR}/MD5" extra.sets
119 cp ${SETS_DIR}/SHA512 ${ROOT_DIR}/${DEST_SETS_DIR}
120 add_file_spec "${DEST_SETS_DIR}/SHA512" extra.sets
124 # Add HDD files to the workdir
126 workdir_add_hdd_files()
128 # create a fstab entry in /etc
129 cat >${ROOT_DIR}/etc/fstab <<END_FSTAB
130 /dev/c0d0p1 /usr mfs rw 0 2
131 /dev/c0d0p2 /home mfs rw 0 2
132 none /sys devman rw,rslabel=devman 0 0
133 none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
135 add_file_spec "etc/fstab" extra.fstab
138 cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/boot_monitor
139 add_file_spec "boot_monitor" extra.boot
143 # Add CD boot files to the workdir
145 workdir_add_cd_files()
147 # create a fstab entry in /etc
148 cat >${ROOT_DIR}/etc/fstab <<END_FSTAB
149 none /sys devman rw,rslabel=devman 0 0
150 none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
152 add_file_spec "etc/fstab" extra.fstab
155 cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/minixboot
156 add_file_spec "minixboot" extra.cdfiles
159 cp releasetools/release/cd/README.TXT ${ROOT_DIR}/README.TXT
160 add_file_spec "README.TXT" extra.cdfiles
164 # Add ramdisk files to the workdir
166 workdir_add_ramdisk_files()
168 # create a fstab entry in /etc
169 cat >${ROOT_DIR}/etc/fstab <<END_FSTAB
170 none /sys devman rw,rslabel=devman 0 0
171 none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
173 add_file_spec "etc/fstab" extra.fstab
175 # add early boot rc script
176 cp minix/drivers/storage/ramdisk/rc ${ROOT_DIR}/etc/rc.ramdisk
177 add_file_spec "etc/rc.ramdisk" extra.fstab
180 cp releasetools/release/cd/README.TXT ${ROOT_DIR}/README.TXT
181 add_file_spec "README.TXT" extra.cdfiles
185 # Extract kernel to designated directory
187 # $1: Directory where to extract
190 (cd ${ROOT_DIR}; ${CROSS_TOOLS}/nbpax -rnz -f ${SETS_DIR}/minix-kernel.tgz .)
192 # Move kernel files to the correct directory
193 if [ ! -d ${ROOT_DIR}/boot/$1 ]
195 mkdir -p ${ROOT_DIR}/boot/$1
196 add_dir_spec "boot/$1" extra.kernel
199 mv ${ROOT_DIR}/boot/minix/.temp/* ${ROOT_DIR}/boot/$1
200 rm -rf ${ROOT_DIR}/boot/minix/.temp
201 for i in $(cd ${ROOT_DIR}/boot/$1 && echo *)
203 add_file_spec "boot/$1/$i" extra.kernel
208 # Read METALOG and use mtree to convert the user and group names into uid and gids.
209 # Used as the reference mtree for building file systems.
213 cat ${WORK_DIR}/set* ${WORK_DIR}/extra* | ${CROSS_TOOLS}/nbmtree -N ${ROOT_DIR}/etc -C -K device > ${WORK_DIR}/input
215 if [ ${ASR_HACK} -eq 1 ]
217 # Hacky workaround for ASR-randomized service binaries since they don't get nicely packaged in a tarball
218 # add any generated ASR-randomized service binaries
219 # TODO: apply stricter file permissions for both these and the base /service binaries, against local attacks
220 (cd ${DESTDIR} && find ./usr/service/asr -type f | sed 's/$/ type=file uid=0 gid=0 mode=0755/') >> ${WORK_DIR}/input
221 cp -r ${DESTDIR}/usr/service/asr ${ROOT_DIR}/usr/service
226 # Split mtree into partitions and create proto files for nbmkfs.mfs
228 # $1 : partitions to create (example: usr home)
232 FILTER_COMMAND="cat ${WORK_DIR}/input"
235 FILTER_COMMAND="$FILTER_COMMAND | grep -v \"^./$i/\" "
238 # fill root.img (skipping entries inside partitions while keeping partition mount points)
239 eval $FILTER_COMMAND | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR} -o ${WORK_DIR}/proto.root
241 # create proto files for partitions using toproto
244 cat ${WORK_DIR}/input | grep "^\./$i/\|^. " | sed "s,\./$i,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR}/$i -o ${WORK_DIR}/proto.$i
249 # Clone grub repository and build efi boot binary
251 fetch_and_build_grub()
253 if [ -d ${RELEASETOOLSDIR}/grub ]
255 echo grub is already checked out
257 git clone git://git.savannah.gnu.org/grub.git ${RELEASETOOLSDIR}/grub
258 pushd ${RELEASETOOLSDIR}/grub
259 # most recent known working commit at the time of writing
260 git checkout a0bf403f66dbaca4edd8e667bfc397dd91c8d71c
262 ./configure --with-platform=efi --target=i386
266 ../grub-mkimage -v -d . -o booti386.efi -O i386-efi -p /boot/efi normal part_msdos fat chain boot configfile multiboot minix3 gzio efi_uga
273 # Create grub.cfg for efi boot
277 cat > ${EFI_DIR}/boot/efi/grub.cfg <<END_GRUBCFG
291 menuentry "Minix Boot" {
293 multiboot /boot/minix_default/kernel rootdevname=c0d0p0
294 module /boot/minix_default/mod01_ds
295 module /boot/minix_default/mod02_rs
296 module /boot/minix_default/mod03_pm
297 module /boot/minix_default/mod04_sched
298 module /boot/minix_default/mod05_vfs
299 module /boot/minix_default/mod06_memory
300 module /boot/minix_default/mod07_tty
301 module /boot/minix_default/mod08_mib
302 module /boot/minix_default/mod09_vm
303 module /boot/minix_default/mod10_pfs
304 module /boot/minix_default/mod11_mfs
305 module /boot/minix_default/mod12_init
308 menuentry "Minix Boot (serial)" {
310 multiboot /boot/minix_default/kernel rootdevname=c0d0p0 cttyline=0 ttybaud=115200 console=tty00 consdev=com0
311 module /boot/minix_default/mod01_ds
312 module /boot/minix_default/mod02_rs
313 module /boot/minix_default/mod03_pm
314 module /boot/minix_default/mod04_sched
315 module /boot/minix_default/mod05_vfs
316 module /boot/minix_default/mod06_memory
317 module /boot/minix_default/mod07_tty
318 module /boot/minix_default/mod08_mib
319 module /boot/minix_default/mod09_vm
320 module /boot/minix_default/mod10_pfs
321 module /boot/minix_default/mod11_mfs
322 module /boot/minix_default/mod12_init
328 # Create ramdisk image from root directory
330 # $1 : size of ramdisk (optional)
331 create_ramdisk_image()
333 PATH=$(cd ${CROSS_TOOLS}; pwd):$PATH
338 RAMSIZE="-b $(( $1 / 512 / 8))"
342 _RAMDISKSIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${RAMSIZE} -I 0 ${WORK_DIR}/imgrd.mfs ${WORK_DIR}/proto.root)
343 (cd ${WORK_DIR}; ${TOOLCHAIN_TRIPLET}objcopy -Ibinary -Bi386 -Oi586-elf32-minix imgrd.mfs imgrd.o)
344 ${TOOLCHAIN_TRIPLET}clang --sysroot=${DESTDIR} -L ${DESTDIR}/usr/lib -static -o ${WORK_DIR}/mod06_memory ${OBJ}/minix/drivers/storage/memory/memory.o ${WORK_DIR}/imgrd.o -nodefaultlibs -lblockdriver -lchardriver -lsys -lminc
348 # Bundle packages (won't preinstall them)
350 # $1 : packages to bundle
358 if [ -z $PACKAGE_DIR ]
360 echo "Error: PACKAGE_DIR is not set while trying to bundle packages."
361 echo "Please fetch binary packages to bundle and set PACKAGE_DIR to continue."
365 DESTPACKAGES="usr/packages/$RELEASE_VERSION/$ARCH/All"
366 RELEASEPACKAGE="${ROOT_DIR}/$DESTPACKAGES"
370 mkdir -p $RELEASEPACKAGE
371 add_dir_spec "usr/packages" extra.pkgsrc
372 add_dir_spec "usr/packages/$RELEASE_VERSION" extra.pkgsrc
373 add_dir_spec "usr/packages/$RELEASE_VERSION/$ARCH" extra.pkgsrc
374 add_dir_spec "usr/packages/$RELEASE_VERSION/$ARCH/All" extra.pkgsrc
375 add_link_spec "packages" "usr/packages" extra.pkgsrc
378 realfn=$(echo $PACKAGE_DIR/${pkgprefix}*.tgz | cut -d' ' -f1)
382 p="$(basename $realfn)"
383 echo " * Bundling $p..."
384 cp "$realfn" "$RELEASEPACKAGE/$p"
385 add_file_spec "$DESTPACKAGES/$p" extra.pkgsrc
387 echo "Error: Can't find $pkgprefix in directory $PACKAGE_DIR for bundling package."
392 if [ -x "$(which $PKG_INFO)" ]
394 # Create packages index
395 echo " * Generating package index..."
396 indexname=$indexpath/$p.$index
397 $PKG_INFO -X $RELEASEPACKAGE/*.tgz >> $RELEASEPACKAGE/$index
400 echo " * Compressing index..."
401 bzip2 -f $RELEASEPACKAGE/$index
402 add_file_spec "$DESTPACKAGES/$index.bz2" extra.pkgsrc
404 echo " * Skipping package index generation."
405 echo " PKG_INFO ("$(which $PKG_INFO)") not executable."
410 # stuff executed automatically to set up environment
415 echo "Usage: $0 [options]"
416 echo " -X xsrc Build with X11 located in \"xsrc\""
417 echo " -x Add X11 sets to extraction list"
418 echo " -b Add ASR service binaries to the image"
419 echo " (said binaries must be built beforehand)"
421 echo "Environment variables:"
422 echo " CREATE_IMAGE_ONLY If set to 1, skip invocation of build.sh (default: 0)"
423 echo " JOBS Number of CPUs to use for build.sh to use (default: 1)"
424 echo " SETS Sets to extract for image (default: depends on script)"
425 echo " BUILDVARS Extra options passed to build.sh (default: none)"
427 echo " PACKAGE_DIR Path to packages to bundle (default: none)"
428 echo " BUNDLE_PACKAGES List of packages to bundle (default: none)"
429 echo " PKG_INFO Path to 'pkg_info' for bundling (default: pkg_info)"
431 echo " BUNDLE_SETS If set to 1, bundle sets for setup (default: only for CD)"
435 while getopts "ixX:bh" c
438 i) echo "This method of generating the ISO installation media is obsolete."
439 echo "Run ./releasetools/x86_cdimage.sh instead."
442 x) SETS="$SETS xbase xcomp xetc xfont xserver";;
446 BUILDVARS="$BUILDVARS -X $OPTARG";;
448 b) # bitcode build: increase partition sizes
449 ROOT_SIZE="$((${ROOT_SIZE} + 192*(2**20)))"
450 USR_SIZE="$((${USR_SIZE} + 256*(2**20)))"
466 # Are we going to build the minix sources?
469 if [ ${CREATE_IMAGE_ONLY} -eq 1 ]
471 if [ ! -d ${DESTDIR} ]
473 echo "Minix source code doesn't appear to have been built."
474 echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
477 if [ ! -d ${RELEASEDIR} ]
479 echo "Minix release tarball sets don't appear to have been created."
480 echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
483 # FIXME: this won't change anything for tarballs
484 #${CROSS_TOOLS}/nbmake-i386 -C releasetools do-hdboot
486 echo "Going to build Minix source code..."
488 # Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'.
493 # Now start the build.
495 sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u release
500 if [ -d "${WORK_DIR}/.git" ]
502 echo "WORK_DIR directory has a Git repository in it, abort!"
506 # clean working directory
507 if [ -e "${WORK_DIR}" ]
513 # get absolute paths to those directories
514 CROSS_TOOLS=$(cd ${CROSS_TOOLS} && pwd)
515 DESTDIR=$(cd ${DESTDIR} && pwd)
516 MODDIR=$(cd ${MODDIR} && pwd)
517 OBJ=$(cd ${OBJ} && pwd)
518 SETS_DIR=$(cd ${SETS_DIR} && pwd)
519 WORK_DIR=$(cd ${WORK_DIR} && pwd)
520 ROOT_DIR=${WORK_DIR}/fs
523 mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`"