Skip to main content

max / mountaineer

4.0 KB · 117 lines History Blame Raw
1 #!/bin/sh
2 # build.sh — Mountaineer top-level build entry point.
3 #
4 # What it does (in order):
5 # 1. Build the apkovl tarball from apkovl-src/.
6 # 2. If running on an Alpine host with the build tools present, invoke
7 # mkimage with the Mountaineer Server profile and the apkovl from
8 # step 1.
9 # 3. If not on Alpine (or tools missing), print the canonical podman
10 # invocation that runs this same script inside an Alpine container.
11 # Mountaineer does not try to be clever and auto-launch the container
12 # — the operator chooses to run it themselves.
13 #
14 # Build environments documented in BUILD-TOOLS.md.
15
16 set -eu
17
18 here() { cd "$(dirname "$0")" && pwd; }
19 ROOT="$(here)"
20 PROFILE="${PROFILE:-server}"
21 APORTS="${APORTS:-$ROOT/.aports}"
22 OUTDIR="${OUTDIR:-$ROOT/out}"
23
24 mkdir -p "$OUTDIR"
25
26 # --- step 1: standalone target apkovl ------------------------------------
27 # Build the *target* apkovl as a standalone artifact in out/. This is the
28 # apkovl an operator would use to fleet-provision an already-installed
29 # Mountaineer host (drop it in /var/lib/mountaineer/ and reboot, or
30 # similar). The *live* apkovl (with installer + target embedded) is built
31 # by mkimage's genapkovl-mountaineer-server.sh in step 2.
32 echo "==> building target apkovl"
33 "$ROOT/tools/build-apkovl.sh" server-target
34
35 # --- step 2: detect build environment -----------------------------------
36 on_alpine() {
37 [ -f /etc/alpine-release ]
38 }
39
40 have_tool() {
41 command -v "$1" >/dev/null 2>&1
42 }
43
44 if ! on_alpine; then
45 cat <<EOF
46
47 Not running on Alpine — stopping after the apkovl build.
48
49 The apkovl is at:
50 $APKOVL
51
52 To build the ISO, run this script inside an Alpine container with the
53 build tools mounted in. Canonical invocation:
54
55 podman run --rm -it --privileged \\
56 -v $ROOT:/build \\
57 -w /build \\
58 docker.io/alpine:edge \\
59 sh -c 'apk add alpine-sdk abuild xorriso squashfs-tools mkinitfs grub-efi git && ./build.sh'
60
61 Or on an Alpine host directly:
62
63 apk add alpine-sdk abuild xorriso squashfs-tools mkinitfs grub-efi git
64 ./build.sh
65
66 EOF
67 exit 0
68 fi
69
70 # On Alpine — verify tools and aports checkout exist.
71 missing=
72 for tool in abuild xorriso mksquashfs mkinitfs; do
73 have_tool "$tool" || missing="$missing $tool"
74 done
75 if [ -n "$missing" ]; then
76 echo "error: missing tools on this Alpine host:$missing" >&2
77 echo " apk add alpine-sdk abuild xorriso squashfs-tools mkinitfs" >&2
78 exit 1
79 fi
80
81 if [ ! -d "$APORTS" ]; then
82 echo "==> cloning aports into $APORTS (shallow)"
83 git clone --depth 1 https://gitlab.alpinelinux.org/alpine/aports.git "$APORTS"
84 fi
85
86 # Stage the Mountaineer mkimg profile + genapkovl script into the aports tree.
87 # mkimage looks up profiles by `profile_$NAME` shell function, so the name
88 # must be a valid shell identifier — underscore, not hyphen.
89 cp "$ROOT/mkimg/mkimg.mountaineer_server.sh" "$APORTS/scripts/"
90 cp "$ROOT/mkimg/genapkovl-mountaineer-server.sh" "$APORTS/scripts/"
91 chmod +x "$APORTS/scripts/genapkovl-mountaineer-server.sh"
92
93 # mkimage's apkovl section caches output in .work/apkovl_<profile>/ keyed
94 # only by section name — it does NOT incorporate the genapkovl script's
95 # content hash (unlike most other sections). So if apkovl-src/ changes,
96 # mkimage silently reuses the previous apkovl. Workaround: blow away the
97 # apkovl section dir on every build, plus the downstream image section
98 # (the ISO embeds the apkovl, so it must be re-assembled too).
99 WORKDIR="$ROOT/.work"
100 rm -rf "$WORKDIR"/apkovl_* "$WORKDIR"/image-*
101
102 # --- step 3: mkimage -----------------------------------------------------
103 echo "==> running mkimage (this takes a while)"
104 cd "$APORTS"
105 export MOUNTAINEER_SRC="$ROOT"
106 sh scripts/mkimage.sh \
107 --tag v3.23 \
108 --outdir "$OUTDIR" \
109 --arch x86_64 \
110 --profile mountaineer_server \
111 --workdir "$ROOT/.work" \
112 --repository https://dl-cdn.alpinelinux.org/alpine/v3.23/main \
113 --repository https://dl-cdn.alpinelinux.org/alpine/v3.23/community
114
115 echo "==> done"
116 ls -lh "$OUTDIR"/*.iso 2>/dev/null || echo "(no ISO produced — check mkimage output above)"
117