# # spec file handling # # # Add a directory to a spec file # # $1 : directory to add # $2 : spec file add_dir_spec() { echo "./$1 type=dir uid=0 gid=0 mode=0755" >> ${WORK_DIR}/$2 } # # Add a file to a spec file # # $1 : file to add # $2 : spec file add_file_spec() { echo "./$1 type=file uid=0 gid=0 mode=0755 size=$(wc -c < ${ROOT_DIR}/${1})" >> ${WORK_DIR}/$2 } # # Add a symbolic link to a spec file # # $1 : symlink to add # $2 : link to # $3 : spec file add_link_spec() { echo "./$1 type=link uid=0 gid=0 mode=0755 link=$2" >> ${WORK_DIR}/$3 } # # workdir handling # # # Create the workdir (a directory where Minix is built using sets) # spec files are put in WORK_DIR, the file system created in ROOT_DIR # # $1 : sets to extract build_workdir() { mkdir -p ${ROOT_DIR} # Don't do anything if we don't use sets if [ -n "$1" ] then # Extract sets for set in $1; do if [ ! -e ${SETS_DIR}/${set}.tgz ]; then echo "Missing ${SETS_DIR}/${set}.tgz, aborting" echo "Are the release sets tarballs created?" exit 1 fi echo " * Extracting $set..." (cd ${ROOT_DIR}; ${CROSS_TOOLS}/nbpax -rnz -f ${SETS_DIR}/${set}.tgz .) done # add rc (if any) if [ -f ${RC} ]; then cp ${RC} ${ROOT_DIR}/usr/etc/rc.local fi # Build login/password files ${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${ROOT_DIR} ${ROOT_DIR}/etc/master.passwd # Build specifications files cp ${ROOT_DIR}/etc/mtree/set* ${WORK_DIR} ${ROOT_DIR}/usr/bin/MAKEDEV -s -m all >> ${WORK_DIR}/extra.dev fi if [ ${BUNDLE_SETS} -eq 1 ] then echo " * Bundling sets..." workdir_add_sets fi } # # Add tarball sets to the workdir (for installation CD) # workdir_add_sets() { # Add sets to the root mkdir -p ${ROOT_DIR}/usr/${ARCH}/binary/sets; add_dir_spec "usr/${ARCH}" extra.sets add_dir_spec "usr/${ARCH}/binary" extra.sets add_dir_spec "usr/${ARCH}/binary/sets" extra.sets add_link_spec "${ARCH}" "usr/${ARCH}" extra.sets DEST_SETS_DIR="usr/${ARCH}/binary/sets" for set in ${SETS_DIR}/*.tgz; do # Copy set itself cp ${set} ${ROOT_DIR}/${DEST_SETS_DIR} add_file_spec "${DEST_SETS_DIR}/$(basename ${set})" extra.sets # Add file count COUNT_SRC=$(echo $(basename ${set}) | sed -e "s/\(.*\)\.tgz/\set.\1/") COUNT_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.count/") if [ -e "${DESTDIR}/etc/mtree/${COUNT_SRC}" ] then wc -l < ${DESTDIR}/etc/mtree/${COUNT_SRC} > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME} else # Can't find mtree file, set bogus number echo 1 > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME} fi add_file_spec "${DEST_SETS_DIR}/${COUNT_NAME}" extra.sets # Add file sizes SIZE_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.size/") ${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} add_file_spec "${DEST_SETS_DIR}/${SIZE_NAME}" extra.sets done # Add checksums cp ${SETS_DIR}/MD5 ${ROOT_DIR}/${DEST_SETS_DIR} add_file_spec "${DEST_SETS_DIR}/MD5" extra.sets cp ${SETS_DIR}/SHA512 ${ROOT_DIR}/${DEST_SETS_DIR} add_file_spec "${DEST_SETS_DIR}/SHA512" extra.sets } # # Add HDD files to the workdir # workdir_add_hdd_files() { # create a fstab entry in /etc cat >${ROOT_DIR}/etc/fstab <${ROOT_DIR}/etc/fstab <${ROOT_DIR}/etc/fstab < ${WORK_DIR}/input else cat ${WORK_DIR}/extra* | ${CROSS_TOOLS}/nbmtree -C > ${WORK_DIR}/input fi if [ ${ASR_HACK} -eq 1 ] then # Hacky workaround for ASR-randomized service binaries since they don't get nicely packaged in a tarball # add any generated ASR-randomized service binaries # TODO: apply stricter file permissions for both these and the base /service binaries, against local attacks (cd ${DESTDIR} && find ./usr/service/asr -type f | sed 's/$/ type=file uid=0 gid=0 mode=0755/') >> ${WORK_DIR}/input cp -r ${DESTDIR}/usr/service/asr ${ROOT_DIR}/usr/service fi } # # Split mtree into partitions and create proto files for nbmkfs.mfs # # $1 : partitions to create (example: usr home) create_protos() { # build filter FILTER_COMMAND="cat ${WORK_DIR}/input" for i in $1 do FILTER_COMMAND="$FILTER_COMMAND | grep -v \"^./$i/\" " done # fill root.img (skipping entries inside partitions while keeping partition mount points) eval $FILTER_COMMAND | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR} -o ${WORK_DIR}/proto.root # create proto files for partitions using toproto for i in $1 do cat ${WORK_DIR}/input | grep "^\./$i/\|^. " | sed "s,\./$i,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR}/$i -o ${WORK_DIR}/proto.$i done } # # Clone grub repository and build efi boot binary # fetch_and_build_grub() { if [ -d ${RELEASETOOLSDIR}/grub ] then echo grub is already checked out else git clone git://git.savannah.gnu.org/grub.git ${RELEASETOOLSDIR}/grub pushd ${RELEASETOOLSDIR}/grub # most recent known working commit at the time of writing git checkout a0bf403f66dbaca4edd8e667bfc397dd91c8d71c ./autogen.sh ./configure --with-platform=efi --target=i386 make clean make -j ${JOBS} cd grub-core ../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 ls -l booti386.efi popd fi } # # Create grub.cfg for efi boot # create_grub_cfg() { cat > ${EFI_DIR}/boot/efi/grub.cfg <> $RELEASEPACKAGE/$index # Compress index echo " * Compressing index..." bzip2 -f $RELEASEPACKAGE/$index add_file_spec "$DESTPACKAGES/$index.bz2" extra.pkgsrc } # # stuff executed automatically to set up environment # usage() { echo "Usage: $0 [options]" echo " -X xsrc Build with X11 located in \"xsrc\"" echo " -x Add X11 sets to extraction list" echo " -b Add ASR service binaries to the image" echo " (said binaries must be built beforehand)" echo "" echo "Environment variables:" echo " CREATE_IMAGE_ONLY If set to 1, skip invocation of build.sh (default: 0)" echo " JOBS Number of CPUs to use for build.sh to use (default: 1)" echo " SETS Sets to extract for image (default: depends on script)" echo " BUILDVARS Extra options passed to build.sh (default: none)" echo "" echo " PACKAGE_DIR Path to packages to bundle (default: none)" echo " BUNDLE_PACKAGES List of packages to bundle (default: none)" echo " PKG_INFO Path to 'pkg_info' for bundling (default: pkg_info)" echo "" echo " BUNDLE_SETS If set to 1, bundle sets for setup (default: only for CD)" } # parse options while getopts "ixX:bh" c do case "$c" in i) echo "This method of generating the ISO installation media is obsolete." echo "Run ./releasetools/x86_cdimage.sh instead." exit 1;; x) SETS="$SETS xbase xcomp xetc xfont xserver";; X) MKX11=yes export MKX11 BUILDVARS="$BUILDVARS -X $OPTARG";; b) # bitcode build: increase partition sizes ROOT_SIZE="$((${ROOT_SIZE} + 192*(2**20)))" USR_SIZE="$((${USR_SIZE} + 256*(2**20)))" ASR_HACK=1;; h) usage exit 0;; :) usage exit 2;; \?) usage exit 2;; esac done # # Are we going to build the minix sources? # if [ ${CREATE_IMAGE_ONLY} -eq 1 ] then if [ ! -d ${DESTDIR} ] then echo "Minix source code doesn't appear to have been built." echo "Please try with \$CREATE_IMAGE_ONLY set to 0." exit 1 fi if [ ! -d ${RELEASEDIR} ] then echo "Minix release tarball sets don't appear to have been created." echo "Please try with \$CREATE_IMAGE_ONLY set to 0." exit 1 fi # FIXME: this won't change anything for tarballs #${CROSS_TOOLS}/nbmake-i386 -C releasetools do-hdboot else echo "Going to build Minix source code..." # # Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'. # rm -f ${FSTAB} # # Now start the build. # sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u release fi # sanity check if [ -d "${WORK_DIR}/.git" ] then echo "WORK_DIR directory has a Git repository in it, abort!" exit 1 fi # clean working directory if [ -e "${WORK_DIR}" ] then rm -rf "${WORK_DIR}" fi mkdir -p ${WORK_DIR} # get absolute paths to those directories CROSS_TOOLS=$(cd ${CROSS_TOOLS} && pwd) DESTDIR=$(cd ${DESTDIR} && pwd) MODDIR=$(cd ${MODDIR} && pwd) OBJ=$(cd ${OBJ} && pwd) SETS_DIR=$(cd ${SETS_DIR} && pwd) WORK_DIR=$(cd ${WORK_DIR} && pwd) ROOT_DIR=${WORK_DIR}/fs # get list of mods mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`"