Skip to main content

max / mountaineer

2.3 KB · 59 lines History Blame Raw
1 #!/bin/sh -e
2 # genapkovl-mountaineer-server.sh — invoked by mkimage's build_apkovl()
3 # to produce <hostname>.apkovl.tar.gz in the current directory.
4 #
5 # This is the seam between mkimage's "give me one apkovl tarball" contract
6 # and Mountaineer's two-apkovl model (live and target). The flow:
7 #
8 # 1. Build the *target* apkovl (apkovl-src/common only).
9 # 2. Stage a dynamic extras directory containing:
10 # usr/local/sbin/mountaineer-install (the installer script)
11 # usr/share/mountaineer/install.apkovl.tar.gz (the target apkovl from step 1)
12 # usr/share/mountaineer/docs/ (MANIFESTO, STACK, ROUTES, INSTALL)
13 # 3. Build the *live* apkovl by merging apkovl-src/common +
14 # apkovl-src/live + the staged extras.
15 # 4. Emit as $HOSTNAME.apkovl.tar.gz in cwd (mkimage's contract).
16 #
17 # Reads MOUNTAINEER_SRC from environment (set by build.sh).
18
19 HOSTNAME="${1:?usage: $0 <hostname>}"
20
21 if [ -z "${MOUNTAINEER_SRC:-}" ]; then
22 echo "error: MOUNTAINEER_SRC env var not set; build.sh should export it" >&2
23 exit 1
24 fi
25
26 BUILD_APKOVL="$MOUNTAINEER_SRC/tools/build-apkovl.sh"
27 INSTALLER="$MOUNTAINEER_SRC/installer/install.sh"
28 SPEC_DIR="$MOUNTAINEER_SRC/../mountaineer"
29
30 for f in "$BUILD_APKOVL" "$INSTALLER"; do
31 [ -x "$f" ] || { echo "error: missing or non-executable: $f" >&2; exit 1; }
32 done
33
34 work=$(mktemp -d)
35 trap 'rm -rf "$work"' EXIT
36
37 target_apkovl="$work/target.apkovl.tar.gz"
38 extras="$work/extras"
39
40 echo "==> genapkovl: building target apkovl" >&2
41 "$BUILD_APKOVL" server-target "$target_apkovl" >&2
42
43 echo "==> genapkovl: staging live extras" >&2
44 mkdir -p "$extras/usr/local/sbin" "$extras/usr/share/mountaineer/docs"
45 cp "$INSTALLER" "$extras/usr/local/sbin/mountaineer-install"
46 chmod +x "$extras/usr/local/sbin/mountaineer-install"
47 cp "$target_apkovl" "$extras/usr/share/mountaineer/install.apkovl.tar.gz"
48
49 # Spec docs from the sibling repo, if present. Don't fail the build if
50 # they aren't (the build can run from a checkout that doesn't have them).
51 if [ -d "$SPEC_DIR" ]; then
52 for doc in MANIFESTO.md STACK.md PROFILES.md ROUTES.md INSTALL.md BUILD-TOOLS.md; do
53 [ -f "$SPEC_DIR/$doc" ] && cp "$SPEC_DIR/$doc" "$extras/usr/share/mountaineer/docs/"
54 done
55 fi
56
57 echo "==> genapkovl: building live apkovl as $PWD/$HOSTNAME.apkovl.tar.gz" >&2
58 "$BUILD_APKOVL" server "$PWD/$HOSTNAME.apkovl.tar.gz" --extra "$extras" >&2
59