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 #ROOT=/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}/obj"
68 mkdir -p "${world}/root"
69 mount -t devfs devfs "${build}/dev" || wtf
70 # Mount /usr/src as a union, so that changes to it will not affect the underlying tree
71 # unionfs suffers from deadlocks; don't use it
72 mount -t nullfs -r /usr/src "${build}/usr/src" || wtf
73 mount -t nullfs "${world}/obj" "${build}/usr/obj" || wtf
74 mount -t nullfs "${world}/root" "${build}/mnt" || wtf
76 if [ -d "${world}/config" ]
78 meh "Installing build-time configuration"
79 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "/usr/src/sys/${TARGET}/conf/"
80 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
81 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"
87 umount -f "${build}/mnt"
88 umount -f "${build}/usr/obj"
89 umount -f "${build}/usr/src"
90 umount -f "${build}/dev"
91 mount | grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
92 chflags -R noschg "${build}"
98 omg "${build}: directory exists; purging"
105 meh "Config: ${TARGET}/${CONFIG}"
106 meh "Builddir: ${build}"
107 meh "make ${MAKEOPTS}"
108 meh "DESTDIR=${world}"
110 for phase in buildworld buildkernel distrib-dirs installworld installkernel distribution
112 meh "==> Phase: ${phase}"
113 script "${world}/${date}-${phase}.log" chroot "${build}" sh -c \
114 "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf
117 # Copy the config files into the target, to keep a record of the build options
118 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "${build}/boot/kernel/"
119 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
120 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"