#!/bin/sh # Building this config: makeopts=-j8 target=amd64 config=SS4200 # Useful defines meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; } omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; } wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; } # Root directory of worlds ROOT="$(realpath "$(dirname "${0}")/..")" # Target directory tgtdir="${target}/${config}" # Check if it exists [ -d "${ROOT}/${tgtdir}" ] || wtf "${tgtdir} doesn't exist" # Construct environment env=" USER=root HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin SHELL=/bin/sh ROOT=${ROOT} MAKEOPTS=${makeopts} TARGET=${target} CONFIG=${config} " # Invoke sanitized environment sudo env -i ${env} sh <<"EOF" # Inherited by env #ROOT=/usr/home/cyberleo/worlds #MAKEOPTS=-j8 #TARGET=amd64 #CONFIG=GENERIC world="${ROOT}/${TARGET}/${CONFIG}" seed="${ROOT}/seed/src" build="${ROOT}/seed/root" date="$(date +%Y%m%d)" # Useful methods meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; } omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; } wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; } prepare() { mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue" # Cleanup trap here, so that an abort during prepare can clean up properly trap "cleanup" exit hup int term kill meh "Preparing build environment" [ -d "${build}" ] && wtf "${build}: directory exists" mkdir -p "${build}" || wtf cat "${seed}"/base.?? | tar xCf "${build}" - || wtf mkdir -p "${build}/usr/obj" || wtf meh "Mounting chroot directories" mkdir -p "${world}/root" mount -t devfs devfs "${build}/dev" || wtf # Mount /usr/src as a union, so that changes to it will not affect the underlying tree # unionfs suffers from deadlocks; don't use it mount -t nullfs -r /usr/src "${build}/usr/src" || wtf mount -t nullfs /usr/obj "${build}/usr/obj" || wtf mount -t nullfs "${world}/root" "${build}/mnt" || wtf if [ -d "${world}/config" ] then meh "Installing build-time configuration" [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "/usr/src/sys/${TARGET}/conf/" [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/" [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/" fi } cleanup() { meh "Cleaning up" umount -f "${build}/mnt" umount -f "${build}/usr/obj" umount -f "${build}/usr/src" umount -f "${build}/dev" mount | grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing" chflags -R noschg "${build}" rm -Rf "${build}" } if [ -d "${build}" ] then omg "${build}: directory exists; purging" cleanup fi prepare meh "Seed: ${seed}" meh "Config: ${TARGET}/${CONFIG}" meh "Builddir: ${build}" meh "make ${MAKEOPTS}" meh "DESTDIR=${world}" for phase in buildworld buildkernel distrib-dirs installworld installkernel distribution do meh "==> Phase: ${phase}" script "${world}/${date}-${phase}.log" chroot "${build}" sh -c \ "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf done # Copy the config files into the target, to keep a record of the build options [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "${build}/boot/kernel/" [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/" [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/" EOF