3 # Building this config:
9 meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; }
10 omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; }
11 wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; }
13 # Root directory of worlds
14 ROOT="$(realpath "$(dirname "${0}")")"
17 tgtdir="${target}/${config}"
20 [ -d "${ROOT}/${tgtdir}" ] || wtf "${tgtdir} doesn't exist"
22 # Construct environment
26 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
35 # Invoke sanitized environment
36 sudo env -i ${env} sh <<"EOF"
38 #HOME=/usr/home/cyberleo/worlds
43 world="${ROOT}/${TARGET}/${CONFIG}"
45 seed="${ROOT}/seed/src"
46 build="${ROOT}/seed/root"
48 date="$(date +%Y%m%d)"
51 meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; }
52 omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; }
53 wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; }
55 mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue"
57 # Cleanup trap here, so that an abort during prepare can clean up properly
58 trap "cleanup" exit hup int term kill
60 meh "Preparing build environment"
61 [ -d "${build}" ] && wtf "${build}: directory exists"
62 mkdir -p "${build}" || wtf
63 cat "${seed}"/base.?? | tar xCf "${build}" - || wtf
64 mkdir -p "${build}/usr/obj" || wtf
66 meh "Mounting chroot directories"
67 mkdir -p "${world}/root"
68 mount -t devfs devfs "${build}/dev" || wtf
69 # Mount /usr/src as a union, so that changes to it will not affect the underlying tree
70 # unionfs suffers from deadlocks; don't use it
71 mount -t nullfs -r /usr/src "${build}/usr/src" || wtf
72 mount -t nullfs /usr/obj "${build}/usr/obj" || wtf
73 mount -t nullfs "${world}/root" "${build}/mnt" || wtf
75 if [ -d "${world}/config" ]
77 meh "Installing build-time configuration"
78 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "/usr/src/sys/${TARGET}/conf/"
79 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
80 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"
86 umount -f "${build}/mnt"
87 umount -f "${build}/usr/obj"
88 umount -f "${build}/usr/src"
89 umount -f "${build}/dev"
90 mount | grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
91 chflags -R noschg "${build}"
97 omg "${build}: directory exists; purging"
104 meh "Config: ${TARGET}/${CONFIG}"
105 meh "Builddir: ${build}"
106 meh "make ${MAKEOPTS}"
107 meh "DESTDIR=${world}"
109 for phase in buildworld buildkernel distrib-dirs installworld installkernel distribution
111 meh "==> Phase: ${phase}"
112 script "${world}/${date}-${phase}.log" chroot "${build}" sh -c \
113 "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf
116 # Copy the config files into the target, to keep a record of the build options
117 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "${build}/boot/kernel/"
118 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
119 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"