|
1 | 1 | #!/bin/bash |
2 | 2 | # vim: softtabstop=2 shiftwidth=2 expandtab |
3 | 3 |
|
| 4 | +error() { |
| 5 | + echo "ERROR:" "$@" |
| 6 | + exit 1 |
| 7 | +} |
| 8 | + |
4 | 9 | cleanup() { |
5 | | - test -d "${temp}" && rm -rf "${temp}" |
| 10 | + test -d "${buildtmp}" && rm -rf "${buildtmp}" |
| 11 | + unset buildtmp |
6 | 12 | exit |
7 | 13 | } |
8 | 14 |
|
9 | | -release="${1?ERROR: no release version specified}" |
| 15 | +unset buildtmp |
10 | 16 | trap cleanup EXIT INT TERM |
11 | | -temp="$( mktemp -d )" |
12 | 17 |
|
13 | | -if [ ! -d /usr/lib/dracut ]; then |
14 | | - echo "ERROR: missing /usr/lib/dracut" |
15 | | - exit 1 |
16 | | -fi |
| 18 | +# Accept release with or without a leading "v" |
| 19 | +release="${1#v}" |
17 | 20 |
|
18 | | -DRACUTBIN="$( command -v dracut )" |
19 | | -if [ ! -x "${DRACUTBIN}" ]; then |
20 | | - echo "ERROR: missing dracut script" |
21 | | - exit 1 |
22 | | -fi |
| 21 | +case "${release}" in |
| 22 | + "") error "usage: $0 <release> [buildtag]" ;; |
| 23 | + */*) error "release must NOT contain a forward slash" ;; |
| 24 | + *) ;; |
| 25 | +esac |
23 | 26 |
|
24 | | -assets="$( realpath -e releng)/assets/${release}" |
25 | | -if [ -d "${assets}" ]; then |
26 | | - rm -f "${assets}"/* |
27 | | -else |
28 | | - mkdir -p "${assets}" |
29 | | -fi |
| 27 | +buildtag="${2:-localhost/zbm-builder:$(date '+%Y%m%d')}" |
| 28 | +if ! podman inspect "${buildtag}" >/dev/null 2>&1; then |
| 29 | + if ! bldctx="$( realpath -e contrib/docker )"; then |
| 30 | + error "missing contrib/docker, cannot create image ${buildtag}" |
| 31 | + fi |
| 32 | + |
| 33 | + if ZBM_COMMIT_HASH="$(git rev-parse HEAD)" && [ -n "${ZBM_COMMIT_HASH}" ]; then |
| 34 | + build_args=( "--build-arg=ZBM_COMMIT_HASH=${ZBM_COMMIT_HASH}" ) |
| 35 | + else |
| 36 | + build_args=() |
| 37 | + fi |
30 | 38 |
|
31 | | -cp -a /usr/lib/dracut "${temp}" |
32 | | -cp "${DRACUTBIN}" "${temp}/dracut" |
| 39 | + if ! podman build -t "${buildtag}" "${build_args[@]}" "${bldctx}"; then |
| 40 | + error "failed to create builder image" |
| 41 | + fi |
| 42 | +fi |
33 | 43 |
|
34 | | -cp -Rp etc/zfsbootmenu/dracut.conf.d "${temp}" |
| 44 | +buildtmp="$( mktemp -d )" |
35 | 45 |
|
36 | | -cat << EOF > "${temp}/dracut.conf.d/release.conf" |
37 | | -omit_drivers+=" amdgpu radeon nvidia nouveau i915 " |
38 | | -omit_dracutmodules+=" qemu qemu-net crypt-ssh nfs lunmask network network-legacy kernel-network-modules " |
39 | | -embedded_kcl="rd.hostonly=0" |
40 | | -release_build=1 |
41 | | -zfsbootmenu_teardown+=" $( realpath contrib/xhci-teardown.sh ) " |
42 | | -EOF |
| 46 | +mkdir -p "${buildtmp}/dracut.conf.d" |
43 | 47 |
|
44 | | -_dracut_mods="${temp}/dracut/modules.d" |
45 | | -if [ -d "${_dracut_mods}/90zfsbootmenu" ] ; then |
46 | | - if ! rm -rf "${_dracut_mods}/90zfsbootmenu" ; then |
47 | | - echo "Unable to remove ${_dracut_mods}/90zfsbootmenu" |
48 | | - exit 1 |
49 | | - fi |
| 48 | +# Copy default dracut configuration and include a release-specific config |
| 49 | +if ! cp etc/zfsbootmenu/dracut.conf.d/* "${buildtmp}/dracut.conf.d"; then |
| 50 | + error "failed to copy dracut configuration" |
50 | 51 | fi |
51 | 52 |
|
52 | | -ln -s "$(realpath -e 90zfsbootmenu)" "${_dracut_mods}" |
53 | | -ln -s "$(realpath -e bin/generate-zbm)" "${temp}/generate-zbm" |
| 53 | +cat <<-EOF > "${buildtmp}/dracut.conf.d/release.conf" |
| 54 | + zfsbootmenu_teardown+="/zbm/contrib/xhci-teardown.sh" |
| 55 | + install_optional_items+=" /etc/zbm-commit-hash " |
| 56 | + omit_drivers+=" amdgpu radeon nvidia nouveau i915 " |
| 57 | + omit_dracutmodules+=" network network-legacy kernel-network-modules " |
| 58 | + omit_dracutmodules+=" qemu qemu-net crypt-ssh nfs lunmask " |
| 59 | + embedded_kcl="rd.hostonly=0" |
| 60 | + release_build=1 |
| 61 | +EOF |
| 62 | + |
| 63 | +yamlconf="${buildtmp}/config.yaml" |
54 | 64 |
|
55 | | -yamlconf="${temp}/local.yaml" |
56 | | -cp etc/zfsbootmenu/config.yaml "${yamlconf}" |
57 | | -build="${temp}/build" |
| 65 | +if ! cp etc/zfsbootmenu/config.yaml "${yamlconf}"; then |
| 66 | + error "failed to copy default ZFSBootMenu configuration" |
| 67 | +fi |
58 | 68 |
|
59 | 69 | arch="$( uname -m )" |
60 | 70 | BUILD_EFI="false" |
61 | 71 |
|
62 | 72 | case "${arch}" in |
63 | | - x86_64) |
64 | | - BUILD_EFI="true" |
65 | | - ;; |
66 | | - *) |
67 | | - ;; |
| 73 | + x86_64) BUILD_EFI="true" ;; |
| 74 | + *) ;; |
68 | 75 | esac |
69 | 76 |
|
| 77 | +zbmtriplet="zfsbootmenu-${arch}-v${release}" |
| 78 | + |
| 79 | +# Modify the YAML configuration for the containerized build |
70 | 80 | yq-go eval ".Components.Enabled = true" -i "${yamlconf}" |
71 | 81 | yq-go eval ".Components.Versions = false" -i "${yamlconf}" |
72 | | -yq-go eval ".Components.ImageDir = \"${build}\"" -i "${yamlconf}" |
| 82 | +yq-go eval ".Components.ImageDir = \"/build/${zbmtriplet}\"" -i "${yamlconf}" |
73 | 83 | yq-go eval ".EFI.Enabled = ${BUILD_EFI}" -i "${yamlconf}" |
74 | 84 | yq-go eval ".EFI.Versions = false" -i "${yamlconf}" |
75 | | -yq-go eval ".EFI.ImageDir = \"${build}\"" -i "${yamlconf}" |
| 85 | +yq-go eval ".EFI.ImageDir = \"/build/uefi\"" -i "${yamlconf}" |
76 | 86 | yq-go eval ".Global.ManageImages = true" -i "${yamlconf}" |
77 | | -yq-go eval ".Global.DracutConfDir = \"${temp}/dracut.conf.d\"" -i "${yamlconf}" |
78 | | -yq-go eval ".Global.DracutFlags = [ \"--local\", \"--no-early-microcode\" ]" -i "${yamlconf}" |
| 87 | +yq-go eval ".Global.DracutConfDir = \"/build/dracut.conf.d\"" -i "${yamlconf}" |
| 88 | +yq-go eval ".Global.DracutFlags = [ \"--no-early-microcode\" ]" -i "${yamlconf}" |
| 89 | +yq-go eval ".Kernel.CommandLine = \"loglevel=4 nomodeset\"" -i "${yamlconf}" |
79 | 90 | yq-go eval "del(.Global.BootMountPoint)" -i "${yamlconf}" |
80 | | -yq-go eval "del(.Kernel.CommandLine)" -i "${yamlconf}" |
81 | 91 |
|
82 | | -if ! ( cd "${temp}" && PATH=./dracut:${PATH} ./generate-zbm \ |
83 | | - --version "${release}" \ |
84 | | - --config "${yamlconf}" \ |
85 | | - --cmdline "loglevel=4 nomodeset" ) ; then |
| 92 | +# For the containerized build, use current repo by mounting at /zbm |
| 93 | +# Custom configs and outputs will be in the temp dir, mounted at /build |
| 94 | +podman run --rm -v ".:/zbm:ro" -v "${buildtmp}:/build" "${buildtag}" "/build" || exit 1 |
86 | 95 |
|
87 | | - echo "ERROR: Unable to create images" |
88 | | - exit 1 |
| 96 | +if ! assets="$( realpath -e releng )/assets/${release}"; then |
| 97 | + error "unable to define path to built assets" |
| 98 | +fi |
| 99 | + |
| 100 | +if [ -d "${assets}" ]; then |
| 101 | + rm -f "${assets}"/* |
| 102 | +else |
| 103 | + mkdir -p "${assets}" |
89 | 104 | fi |
90 | 105 |
|
91 | 106 | # EFI file is currently only built on x86_64 |
92 | 107 | if [ "${BUILD_EFI}" = "true" ]; then |
93 | | - mv "${build}/vmlinuz.EFI" "${assets}/zfsbootmenu-${arch}-v${release}.EFI" |
| 108 | + cp "${buildtmp}/uefi/vmlinuz.EFI" "${assets}/${zbmtriplet}.EFI" || exit 1 |
94 | 109 | fi |
95 | 110 |
|
96 | 111 | # Components are always built |
97 | | -components="${build}/zfsbootmenu-${arch}-v${release}" |
98 | | -mkdir -p "${components}" |
99 | | -mv "${build}/initramfs-bootmenu.img" "${components}" |
100 | | -mv "${build}/vmlinuz-bootmenu" "${components}" |
101 | | - |
102 | | -( cd "${build}" && tar czvf "${assets}/zfsbootmenu-${arch}-v${release}.tar.gz" "$( basename "${components}" )" ) || exit 1 |
| 112 | +( cd "${buildtmp}" && tar czvf "${assets}/${zbmtriplet}.tar.gz" "${zbmtriplet}" ) || exit 1 |
0 commit comments