From fffd8a5999da7b60708a1e311df024572988aee5 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sun, 25 Jul 2010 22:11:14 -0500 Subject: [PATCH] script/makeworld: perform a chrooted build and install world/kernel according to staged config --- script/makeworld | 120 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 script/makeworld diff --git a/script/makeworld b/script/makeworld new file mode 100755 index 0000000..373f024 --- /dev/null +++ b/script/makeworld @@ -0,0 +1,120 @@ +#!/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 +#HOME=/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 -- 2.42.0