From eaa0b4bac9d3e91047ff7cffaff787a2a7a424e5 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Fri, 15 Oct 2010 12:09:20 -0500 Subject: [PATCH] script/makeworld: refactor to eliminate sudo dependency and reduce sanitized environment to chroot only --- script/makeworld | 92 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/script/makeworld b/script/makeworld index 320c8de..795357c 100755 --- a/script/makeworld +++ b/script/makeworld @@ -1,69 +1,61 @@ #!/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}" +# Root directory of makeworld +ROOT="$(realpath "$(dirname "${0}")/../worlds")" + +# Makeworld dir structure should contain, at minimum: +# script +# makeworld (this file) +# seed +# base +# (arch of build host: i386, amd64, etc) +# base.* (virgin base tree of same arch as host, used to seed chroot for clean build) +# (i386, amd64, etc) +# (GENERIC, SABA, SS4200, etc) +# config +# make.conf +# src.conf +# CONFIG (Matches config name: GENERIC, SABA, SS4200, etc) + +# Going to build this config: +TARGET="${TARGET:-i386}" +CONFIG="${CONFIG:-GENERIC}" +MAKEOPTS="${MAKEOPTS:-"-j4"}" # 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 +[ -d "${ROOT}/${TARGET}/${CONFIG}" ] || wtf "${TARGET}/${CONFIG} doesn't exist" +# Target world directory world="${ROOT}/${TARGET}/${CONFIG}" +# Source chroot seed directory +seed="${ROOT}/seed/base/$(uname -m)" +# Root directory for chroot +build="${ROOT}/seed/chroot-${TARGET}-${CONFIG}" -seed="${ROOT}/seed/src" -build="${ROOT}/seed/root" +# Default build phases +phases="${phases:-buildworld buildkernel distrib-dirs installworld installkernel distribution}" date="$(date +%Y%m%d)" -# Useful methods +# Functions 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 chroot for build 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" + meh "Preparing build chroot" [ -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" + meh "Mounting chroot filesystems" mkdir -p "${world}/obj" mkdir -p "${world}/root" mount -t devfs devfs "${build}/dev" || wtf @@ -82,6 +74,7 @@ prepare() { fi } +# Cleanup chroot cleanup() { meh "Cleaning up" umount -f "${build}/mnt" @@ -106,12 +99,20 @@ meh "Seed: ${seed}" meh "Config: ${TARGET}/${CONFIG}" meh "Builddir: ${build}" meh "make ${MAKEOPTS}" -meh "DESTDIR=${world}" +meh "DESTDIR=${world}/root" + +# Construct environment for chroot build +env=" +USER=root +HOME=/root +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +SHELL=/bin/sh +" -for phase in buildworld buildkernel distrib-dirs installworld installkernel distribution +for phase in ${phases} do meh "==> Phase: ${phase}" - script "${world}/${date}-${phase}.log" chroot "${build}" sh -c \ + script "${world}/${date}-${phase}.log" env -i ${env} chroot "${build}" sh -c \ "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf "chroot-cmd ${phase}" done @@ -119,4 +120,3 @@ done [ -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