]> CyberLeo.Net >> Repos - CDN/Mosi.git/blob - script/makeworld
script/makeworld: complain when seed archives are missing
[CDN/Mosi.git] / script / makeworld
1 #!/bin/sh
2
3 # Boilerplate
4 _root="$(dirname "${0}")"; . "${_root}/lib/env.sh"
5
6 # Load needed modules
7 want root log
8
9 alias meh=log
10 alias omg=warn
11 alias wtf=err
12
13 # Root directory of makeworld
14 ROOT="$(realpath "$(dirname "${0}")/../worlds")"
15
16 # Makeworld dir structure should contain, at minimum:
17 # script
18 #  makeworld (this file)
19 # seed
20 #  base
21 #   <ARCH> (arch of build host: i386, amd64, etc)
22 #    base.* (virgin base tree of same arch as host, used to seed chroot for clean build)
23 # <TARGET> (i386, amd64, etc)
24 #  <CONFIG> (GENERIC, SABA, SS4200, etc)
25 #   config
26 #    make.conf
27 #    src.conf
28 #    CONFIG (Matches config name: GENERIC, SABA, SS4200, etc)
29
30 # Going to build this config:
31 TARGET="${TARGET:-i386}"
32 CONFIG="${CONFIG:-GENERIC}"
33 MAKEOPTS="${MAKEOPTS:-"-j4"}"
34
35 # Check if it exists
36 [ -d "${ROOT}/${TARGET}/${CONFIG}" ] || wtf "${TARGET}/${CONFIG} doesn't exist"
37
38 # Target world directory
39 world="${ROOT}/${TARGET}/${CONFIG}"
40 # Source chroot seed directory
41 seed="${ROOT}/seed/base/$(uname -m)"
42 # Root directory for chroot
43 build="${ROOT}/seed/chroot-${TARGET}-${CONFIG}"
44
45 # Default build phases
46 phases="${phases:-buildworld buildkernel distrib-dirs installworld installkernel distribution}"
47
48 date="$(date +%Y%m%d)"
49
50 # Functions
51
52 # Prepare chroot for build
53 prepare() {
54   mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue"
55
56   # Cleanup trap here, so that an abort during prepare can clean up properly
57   trap "cleanup" exit hup int term kill
58
59   meh "Preparing build chroot"
60   [ -d "${build}" ] && wtf "${build}: directory exists"
61   mkdir -p "${build}" || wtf
62   ls -1 "${seed}"/base.?? >/dev/null 2>&1 || wtf "Populate seed directory ${seed} first"
63   cat "${seed}"/base.?? | tar xCf "${build}" - || wtf
64   mkdir -p "${build}/usr/obj" || wtf
65
66   meh "Mounting chroot filesystems"
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
75
76   if [ -d "${world}/config" ]
77   then
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/"
82   fi
83 }
84
85 # Cleanup chroot
86 cleanup() {
87   meh "Cleaning up"
88   umount -f "${build}/mnt"
89   umount -f "${build}/usr/obj"
90   umount -f "${build}/usr/src"
91   umount -f "${build}/dev"
92   mount | grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
93   chflags -R noschg "${build}"
94   rm -Rf "${build}"
95   trap "" exit hup int term kill
96 }
97
98 if [ -d "${build}" ]
99 then
100   omg "${build}: directory exists; purging"
101   cleanup
102 fi
103
104 prepare
105
106 meh "Seed: ${seed}"
107 meh "Config: ${TARGET}/${CONFIG}"
108 meh "Builddir: ${build}"
109 meh "make ${MAKEOPTS}"
110 meh "DESTDIR=${world}/root"
111
112 # Construct environment for chroot build
113 env="
114 USER=root
115 HOME=/root
116 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
117 SHELL=/bin/sh
118 "
119
120 for phase in ${phases}
121 do
122   meh "==> Phase: ${phase}"
123   script "${world}/${date}-${phase}.log" env -i ${env} chroot "${build}" sh -c \
124     "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf "chroot-cmd ${phase}"
125 done
126
127 # Copy the config files into the target, to keep a record of the build options
128 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "${build}/boot/kernel/"
129 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
130 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"