#!/bin/sh # Runs INSIDE the everest-build image (started by everest.sh). # /everest this project (read-write: pkgs/, boot/) # /glacier-ng glacier-ng checkout (read-only: gbuild, lib/) # /libglacier-ng libglacier-ng checkout (read-only, built in /tmp) # /keys the signing keys (build: read-only; keygen: read-write) # # container.sh keygen make /keys/$KEY_NAME.{sec,pub}, and copy the # public key into everest-repos # container.sh build PKG build one package into /everest/pkgs, signed # container.sh adopt DIR take packages built from recipes into pkgs/ # container.sh publish sign the repositories into /everest/repo # container.sh testca make /everest/testca (local test server) # container.sh initramfs assemble /everest/boot/{vmlinuz,initramfs.gz} set -eu OUT=/everest/pkgs MAINT="liamwaldron@everestlinux.org" # libglacier-ng, built for musl: gbuild needs gsha256sum, and the # initramfs step runs glacier-bootstrap and syspkg with it. cp -a /libglacier-ng /tmp/lg make -C /tmp/lg >/tmp/lg-build.log 2>&1 || { tail -30 /tmp/lg-build.log; exit 1; } export GSHA256SUM_BIN=/tmp/lg/build/bin/gsha256sum export GSIGN_BIN=/tmp/lg/build/bin/gsign KEY_NAME="${KEY_NAME:?}" KEY="/keys/$KEY_NAME.sec" # The public key and repos.conf everest-repos ships; the build host # trusts the same (initramfs, below). TRUST=/everest/pkgsrc/everest-repos/etc/glacier # Hand everything we write back to the invoking user. give_back() { chown -R "${HOST_UID:-0}:${HOST_GID:-0}" "$@"; } # Tarball sources are pinned by SHA256 (checked against upstream's # signatures when the hash was written down) and cached in sources/. SRC=/everest/sources # The toolchain's target: native x86_64 musl, under Everest's own name. TRIPLE=x86_64-everest-linux-musl # fetch URL SHA256: download URL into sources/ (unless the cached copy # has SHA256), refuse it on a mismatch, unpack a tarball into a fresh # directory and print the tree it made; for any other file, print the # directory holding a copy. fetch() { f="$SRC/${1##*/}" mkdir -p "$SRC" if ! echo "$2 $f" | sha256sum -c --status 2>/dev/null; then curl -sfL --proto =https -o "$f.part" "$1" || { echo "[x] Cannot fetch $1" >&2; exit 1; } if ! echo "$2 $f.part" | sha256sum -c --status; then rm -f "$f.part" echo "[x] $1 does not match its hash." >&2 exit 1 fi mv "$f.part" "$f" give_back "$SRC" fi d=$(mktemp -d /tmp/src.XXXXXX) case $f in *.tar.*|*.tgz) tar -xf "$f" -C "$d" && echo "$d"/* ;; *) cp "$f" "$d/" && echo "$d" ;; esac } LIBRESSL_URL=https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-4.3.3.tar.gz LIBRESSL_SHA=ff97c432457f349e6ba3d416ab903bc7468f1436f0f32efe5fff808de292c7b8 LIBRESSL_CONF='./configure --prefix=/usr --sysconfdir=/etc --disable-static --disable-tests' LINUX_URL=https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.12.112.tar.xz LINUX_SHA=164dc9d1f6c93c61a15e1f071c48379b467f2b17c469cce7223471968208ed03 # gcc and gcc-libs come from ONE build: gcc-libs (base) is the runtime # C++/libgcc libraries programs load, gcc (extra) everything else. # The runtime files: versioned shared objects (lib*.so.N...), not the # gdb pretty-printer scripts beside them. # libcc1 is GDB's compiler plugin: gcc's, not a runtime library. gcc_runtime() { (cd "$1" && find usr/lib -maxdepth 1 -name 'lib*.so.*' ! -name '*.py' ! -name 'libcc1.*'); } build_gcc() { s=$(fetch https://ftp.gnu.org/gnu/gcc/gcc-16.2.0/gcc-16.2.0.tar.xz \ e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e) # gmp, mpfr, mpc, isl: built into gcc. The script checks each # against the sha512s in the (signed) gcc tarball. (cd "$s" && ./contrib/download_prerequisites) # One libdir: x86_64 would otherwise put its libraries in lib64. sed -i 's,m64=../lib64,m64=../lib,' "$s/gcc/config/i386/t-linux64" mkdir "$s/build" (cd "$s/build" && ../configure --prefix=/usr \ --build=$TRIPLE --host=$TRIPLE --target=$TRIPLE \ --enable-languages=c,c++ --disable-multilib --disable-bootstrap \ --disable-nls --disable-libsanitizer --disable-libssp \ --disable-symvers --enable-default-pie --enable-default-ssp \ --enable-shared --enable-threads=posix --enable-__cxa_atexit \ --enable-checking=release --with-system-zlib --without-zstd \ --with-local-prefix=/glacier/sys/links \ --with-pkgversion="Everest" && make -j"$(nproc)" && \ make DESTDIR=/tmp/gcc-dest install-strip) rm -f /tmp/gcc-dest/usr/share/info/dir # POSIX's name for the C compiler: plain Makefiles (zstd's) call cc. ln -s gcc /tmp/gcc-dest/usr/bin/cc gcc_runtime /tmp/gcc-dest > /tmp/gcc-runtime [ -s /tmp/gcc-runtime ] || { echo "[x] gcc installed no runtime libraries" >&2; exit 1; } ./gbuild -k "$KEY" -n gcc-libs -V 16.2.0 -g base -c "GPL-3.0-or-later WITH GCC-exception-3.1" -m "$MAINT" \ -d "GCC's runtime libraries (libgcc_s, libstdc++, ...)" \ -D musl:1.2.5 \ -b ':' \ -i 'mkdir -p "$DESTDIR/usr/lib" && cp -P $(cat /tmp/gcc-runtime) "$DESTDIR/usr/lib/"' \ -o "$OUT" /tmp/gcc-dest ./gbuild -k "$KEY" -n gcc -V 16.2.0 -g extra -c "GPL-3.0-or-later" -m "$MAINT" \ -d "The GNU C and C++ compilers" \ -D musl:1.2.5 -D gcc-libs:16.2.0 -D binutils:2.47.0 -D zlib:1.3.2 \ -b ':' \ -i 'cp -a usr "$DESTDIR/" && (cd "$DESTDIR" && rm -f $(cat /tmp/gcc-runtime))' \ -o "$OUT" /tmp/gcc-dest } keygen() { "$GSIGN_BIN" -G -p "/keys/$KEY_NAME.pub" -s "$KEY" -c "$KEY_NAME" mkdir -p "$TRUST/keys" install -m 644 "/keys/$KEY_NAME.pub" "$TRUST/keys/$KEY_NAME.pub" give_back /keys "$TRUST" } build() { cd /glacier-ng case "$1" in musl) ./gbuild -k "$KEY" -n musl -V 1.2.5 -g base -c MIT -m "$MAINT" \ -d "The musl C library" \ -u https://git.musl-libc.org/git/musl -r v1.2.5 \ -b './configure --prefix=/usr --syslibdir=/lib && make -j"$(nproc)"' \ -i 'make DESTDIR="$DESTDIR" install' \ -o "$OUT" ;; busybox) # CONFIG_TC: the tc applet doesn't build against current kernel # headers. linuxrc would land at /usr/linuxrc; nothing needs it. ./gbuild -k "$KEY" -n busybox -V 1.37.0 -g base -c GPL-2.0-only -m "$MAINT" \ -d "Init, shell and core utilities in one binary" \ -D musl:1.2.5 \ -u https://git.busybox.net/busybox -r 1_37_0 \ -b 'make defconfig && sed -i "s/^CONFIG_TC=y/# CONFIG_TC is not set/" .config && make -j"$(nproc)"' \ -i 'make CONFIG_PREFIX="$DESTDIR" install && rm -f "$DESTDIR/linuxrc"' \ -o "$OUT" ;; linux) # 6.12 LTS. Plain v6.12 doesn't build with GCC 15. The image goes # under /usr/lib/modules//: base packages only link under # /usr, and copying it to the boot partition is the installer's job. # kvm_guest.config adds virtio for QEMU; drop it for real hardware. # Namespaces and overlayfs: gsandbox's builds (BUILD_DESIGN.txt). # FW_CFG_SYSFS: everest.sh boot hands test files to the VM. ./gbuild -k "$KEY" -n linux -V 6.12.112 -g base -c GPL-2.0-only -m "$MAINT" \ -d "The Linux kernel" \ -u https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git -r v6.12.112 \ -b 'make defconfig && make kvm_guest.config && ./scripts/config -e NAMESPACES -e USER_NS -e PID_NS -e IPC_NS -e UTS_NS -e NET_NS -e OVERLAY_FS -e FW_CFG_SYSFS && make olddefconfig && make -j"$(nproc)" bzImage modules' \ -i 'rel="$(make -s kernelrelease)" && install -Dm644 arch/x86/boot/bzImage "$DESTDIR/usr/lib/modules/$rel/vmlinuz" && make INSTALL_MOD_PATH="$DESTDIR/usr" INSTALL_MOD_STRIP=1 modules_install && rm -f "$DESTDIR/usr/lib/modules/$rel/build"' \ -o "$OUT" ;; everest-bootscripts) # No compilation: the package is pkgsrc/everest-bootscripts/etc. # Modes are kept, ownership isn't (files are packaged as root). ./gbuild -k "$KEY" -n everest-bootscripts -V 1.4.0 -g base -c MIT -m "$MAINT" \ -d "Default boot scripts and /etc files for Everest" \ -D busybox:1.37.0 \ -b ':' \ -i 'cp -R --preserve=mode,timestamps etc "$DESTDIR/"' \ -o "$OUT" /everest/pkgsrc/everest-bootscripts ;; everest-repos) # /etc/glacier/repos.conf and the public keys it lists, so an # installed system knows its repositories (pkgsrc/everest-repos). ./gbuild -k "$KEY" -n everest-repos -V 1.1.0 -g base -c MIT -m "$MAINT" \ -d "Everest's repository list and signing keys" \ -b ':' \ -i 'cp -R --preserve=mode,timestamps etc "$DESTDIR/"' \ -o "$OUT" /everest/pkgsrc/everest-repos ;; # --- glacier itself (ROADMAP 1.4): everything base except doas --- zlib) ./gbuild -k "$KEY" -n zlib -V 1.3.2 -g base -c Zlib -m "$MAINT" \ -d "Compression library (deflate, gzip)" \ -D musl:1.2.5 \ -u https://github.com/madler/zlib -r v1.3.2 \ -b './configure --prefix=/usr && make -j"$(nproc)"' \ -i 'make DESTDIR="$DESTDIR" install' \ -o "$OUT" ;; libarchive) # gzip'd tar is all glacier needs: every optional codec, crypto # library and front-end is off, so nothing links outside the # system (the build image has openssl, xz, ... installed). ./gbuild -k "$KEY" -n libarchive -V 3.8.9 -g base -c BSD-2-Clause -m "$MAINT" \ -d "Archive reading and writing library" \ -D musl:1.2.5 -D zlib:1.3.2 \ -u https://github.com/libarchive/libarchive -r v3.8.9 \ -b 'sh build/autogen.sh && ./configure --prefix=/usr --disable-static --disable-bsdtar --disable-bsdcpio --disable-bsdcat --disable-bsdunzip --disable-acl --disable-xattr --without-xml2 --without-expat --without-openssl --without-mbedtls --without-nettle --without-lzma --without-zstd --without-bz2lib --without-lz4 --without-libb2 --without-iconv && make -j"$(nproc)"' \ -i 'make DESTDIR="$DESTDIR" install' \ -o "$OUT" ;; libconfig) ./gbuild -k "$KEY" -n libconfig -V 1.8.2 -g base -c LGPL-2.1-or-later -m "$MAINT" \ -d "Structured configuration file library" \ -D musl:1.2.5 \ -u https://github.com/hyperrealm/libconfig -r v1.8.2 \ -b 'cmake -B b -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_CXX=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF && cmake --build b -j"$(nproc)"' \ -i 'DESTDIR="$DESTDIR" cmake --install b' \ -o "$OUT" ;; luajit) # LuaJIT has rolling releases: the version is 2.1., # which is what `luajit -v` reports for this commit. # -static-libgcc: its unwinder would otherwise need libgcc_s.so.1, # which Everest doesn't ship (no GCC runtime package). ./gbuild -k "$KEY" -n luajit -V 2.1.1788856981 -g base -c MIT -m "$MAINT" \ -d "Just-in-time compiler for Lua" \ -D musl:1.2.5 \ -u https://github.com/LuaJIT/LuaJIT -r c6ffc141a8762b41703f9287d63d93622a13dd8f \ -b 'make -j"$(nproc)" PREFIX=/usr LDFLAGS=-static-libgcc' \ -i 'make install PREFIX=/usr DESTDIR="$DESTDIR"' \ -o "$OUT" ;; libglacier-ng) # From the mounted checkout, built above in /tmp/lg. gsha256sum # belongs to the later glacier-tools package, not here. ./gbuild -k "$KEY" -n libglacier-ng -V 4.0.0 -g base -c GPL-3.0-only -m "$MAINT" \ -d "The glacier package manager library" \ -D musl:1.2.5 -D libarchive:3.8.9 -D libconfig:1.8.2 \ -b 'make clean && make' \ -i 'mkdir -p "$DESTDIR/usr/bin" && make install PREFIX="$DESTDIR/usr" && rm -r "$DESTDIR/usr/bin"' \ -o "$OUT" /tmp/lg ;; glacier-ng) # syspkg, gpkg and gstore find lib/ beside their REAL path, so # they live in usr/lib/glacier-ng/ and usr/bin/ holds symlinks # into it. lib/glacier points at libglacier-ng's /usr/lib/glacier. # glacier.conf is Everest's (pkgsrc/glacier-ng: BUILD_ROOT and # BUILD_USER set), not glacier-ng's example. ./gbuild -k "$KEY" -n glacier-ng -V 4.0.0 -g base -c GPL-3.0-only -m "$MAINT" \ -d "syspkg, gpkg and gstore" \ -D luajit:2.1.1788856981 -D libglacier-ng:4.0.0 -D busybox:1.37.0 \ -b ':' \ -i 'd="$DESTDIR/usr/lib/glacier-ng" && mkdir -p "$d/lib" "$DESTDIR/usr/bin" "$DESTDIR/etc/glacier" && install -m 755 syspkg gpkg gstore "$d/" && install -m 644 lib/cargs.lua lib/color.lua lib/glacier_cdef.lua lib/gpkg_common.lua lib/gpkg_build.lua lib/build-driver.sh "$d/lib/" && ln -s /usr/lib/glacier "$d/lib/glacier" && for t in syspkg gpkg gstore; do ln -s "../lib/glacier-ng/$t" "$DESTDIR/usr/bin/$t"; done && install -m 644 /everest/pkgsrc/glacier-ng/etc/glacier/glacier.conf "$DESTDIR/etc/glacier/"' \ -o "$OUT" /glacier-ng ;; doas) # extra, not base: replaceable (e.g. by sudo). No PAM: shadow # passwords. /etc/doas.conf comes from everest-bootscripts. ./gbuild -k "$KEY" -n doas -V 6.8.2 -g extra -c ISC -m "$MAINT" \ -d "Run commands as another user (OpenDoas)" \ -D musl:1.2.5 \ -u https://github.com/Duncaen/OpenDoas -r v6.8.2 \ -b './configure --prefix=/usr --without-pam --without-timestamp && make -j"$(nproc)"' \ -i 'make DESTDIR="$DESTDIR" install' \ -o "$OUT" ;; # --- https for glacier (REPO_DESIGN 10a): LibreSSL, curl, CAs --- libressl) # Libraries only: no openssl/ocspcheck programs, and no # /etc/ssl/cert.pem (ca-certificates ships that). s=$(fetch $LIBRESSL_URL $LIBRESSL_SHA) ./gbuild -k "$KEY" -n libressl -V 4.3.3 -g base -c "OpenSSL AND ISC" -m "$MAINT" \ -d "TLS and crypto libraries (libssl, libcrypto, libtls)" \ -D musl:1.2.5 \ -b "$LIBRESSL_CONF"' && make -j"$(nproc)"' \ -i 'make DESTDIR="$DESTDIR" install && rm -f "$DESTDIR/etc/ssl/cert.pem" "$DESTDIR/usr/bin/openssl" "$DESTDIR/usr/bin/ocspcheck" && rm -rf "$DESTDIR/usr/share/man/man1" "$DESTDIR/usr/share/man/man8/ocspcheck.8" && rmdir "$DESTDIR/usr/bin" 2>/dev/null; true' \ -o "$OUT" "$s" ;; ca-certificates) s=$(fetch https://curl.se/ca/cacert-2026-09-25.pem \ a41b5d356aea97a529fe27e0f7316d2f9d946d75927476cf9cf1b90637d00505) ./gbuild -k "$KEY" -n ca-certificates -V 2026.9.25 -g base -c MPL-2.0 -m "$MAINT" \ -d "Mozilla's CA certificates (curl's extract), /etc/ssl/cert.pem" \ -b ':' \ -i 'install -Dm644 cacert-2026-09-25.pem "$DESTDIR/etc/ssl/cert.pem"' \ -o "$OUT" "$s" ;; curl) # Against LibreSSL, not the build image's OpenSSL: that is # removed and the same LibreSSL installed into this (throwaway) # container first. https only matters to glacier; everything # optional is off. apk del -q openssl-dev l=$(fetch $LIBRESSL_URL $LIBRESSL_SHA) (cd "$l" && eval "$LIBRESSL_CONF" >/dev/null && make -j"$(nproc)" >/dev/null && make install >/dev/null) s=$(fetch https://curl.se/download/curl-8.23.0.tar.xz \ 8dadd7d2536a314f982ad05a651b713f426bf7d02cc2c76cffb9796f2218e6c5) ./gbuild -k "$KEY" -n curl -V 8.23.0 -g base -c curl -m "$MAINT" \ -d "URL transfer tool and library (https through LibreSSL)" \ -D musl:1.2.5 -D zlib:1.3.2 -D libressl:4.3.3 -D ca-certificates:2026.9.25 \ -b './configure --prefix=/usr --disable-static --with-openssl --with-ca-bundle=/etc/ssl/cert.pem --without-ca-path --with-zlib --without-libpsl --without-brotli --without-zstd --without-nghttp2 --without-nghttp3 --without-ngtcp2 --without-libidn2 --without-librtmp --without-libssh2 --without-libssh --disable-ldap --disable-ldaps --disable-manual && make -j"$(nproc)"' \ -i 'make DESTDIR="$DESTDIR" install' \ -o "$OUT" "$s" ;; # --- the toolchain (BUILD_DESIGN 1n: extra; its runtime in base) --- linux-headers) # make headers_install, without its rsync: the .h files of # the generated usr/include. s=$(fetch $LINUX_URL $LINUX_SHA) ./gbuild -k "$KEY" -n linux-headers -V 6.12.112 -g extra -c GPL-2.0-only -m "$MAINT" \ -d "Linux kernel headers for userspace" \ -b ':' \ -i 'make headers && find usr/include -type f ! -name "*.h" -delete && mkdir -p "$DESTDIR/usr" && cp -R usr/include "$DESTDIR/usr/"' \ -o "$OUT" "$s" ;; binutils) # ld also searches /glacier/sys/links/lib, where extra's # libraries are linked (gcc: --with-local-prefix, its headers). s=$(fetch https://ftp.gnu.org/gnu/binutils/binutils-2.47.tar.xz \ 154ab23b60070e8f27013c22977f1129425d67d1e8acd6e13010e617811e4cff) ./gbuild -k "$KEY" -n binutils -V 2.47.0 -g extra -c GPL-3.0-or-later -m "$MAINT" \ -d "Assembler, linker and binary tools" \ -D musl:1.2.5 -D zlib:1.3.2 \ -b "mkdir build && cd build && ../configure --prefix=/usr --build=$TRIPLE --host=$TRIPLE --target=$TRIPLE --disable-nls --disable-werror --disable-multilib --enable-deterministic-archives --enable-ld=default --enable-plugins --enable-64-bit-bfd --disable-gprofng --disable-gdb --disable-gdbserver --disable-sim --with-system-zlib --without-zstd --without-debuginfod --with-lib-path=/usr/lib:/glacier/sys/links/lib"' && make -j"$(nproc)"' \ -i 'make -C build DESTDIR="$DESTDIR" install-strip && rm -f "$DESTDIR/usr/share/info/dir"' \ -o "$OUT" "$s" ;; make) # gnu17: make 4.4.1's old-style declarations aren't C23 (GCC 15+'s # default). s=$(fetch https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz \ dd16fb1d67bfab79a72f5e8390735c49e3e8e70b4945a15ab1f81ddb78658fb3) ./gbuild -k "$KEY" -n make -V 4.4.1 -g extra -c GPL-3.0-or-later -m "$MAINT" \ -d "GNU make" \ -D musl:1.2.5 \ -b './configure --prefix=/usr --disable-nls --without-guile CFLAGS="-O2 -std=gnu17" && make -j"$(nproc)"' \ -i 'make DESTDIR="$DESTDIR" install && rm -f "$DESTDIR/usr/share/info/dir"' \ -o "$OUT" "$s" ;; gcc|gcc-libs) build_gcc ;; *) echo "unknown package: $1" >&2 exit 1 ;; esac give_back "$OUT" } # adopt DIR: packages built from extra-src recipes (the kept # REPO@NAME-VER.gpkg files of a builder's /build/packages) become # pkgs/NAME-VER.gpkg, sidecar written and signed as build does. The # package each replaces moves to pkgs/stage1/ (kept once: the first # build, from the build image's toolchain). Nothing is trusted from # DIR but what the name and the manifest agree on; publish signs the # indexes afterwards. adopt() { mkdir -p "$OUT/stage1" for f in "$1"/*@*.gpkg; do [ -f "$f" ] || { echo "[x] No REPO@NAME-VER.gpkg files in $1." >&2; exit 1; } b=${f##*/}; repo=${b%%@*}; p=${b#*@}; p=${p%.gpkg} m=$(tar -xzOf "$f" "$p/manifest.gpm.cfg") || { echo "[x] $b has no $p/manifest.gpm.cfg." >&2; exit 1; } r=$(echo "$m" | sed -n 's/^PKG_REPO *= *"\(.*\)";$/\1/p') [ "$r" = "$repo" ] || { echo "[x] $b says repository '$r'." >&2; exit 1; } if [ -f "$OUT/$p.gpkg" ] && [ ! -f "$OUT/stage1/$p.gpkg" ]; then mv "$OUT/$p.gpkg"* "$OUT/stage1/" fi cp "$f" "$OUT/$p.gpkg" "$GSHA256SUM_BIN" "$OUT/$p.gpkg" > "$OUT/$p.gpkg.sha256" "$GSIGN_BIN" -S -s "$KEY" -m "$OUT/$p.gpkg.sha256" >/dev/null echo "Adopted $repo::$p" done give_back "$OUT" } # The repositories, signed, in /everest/repo/{base,extra,extra-src}: # every package templates/minimal.template installs plus EXTRA_PKGS # (extra packages the image doesn't install; none today: the toolchain # is in the template), each in the repository its manifest names (so # base is exactly the template's base packages), and every recipe in # /everest/recipes/extra-src. Built in repo.new and swapped in, so a # failure leaves the old tree. EXTRA_PKGS="" REPO=/everest/repo publish() { rm -rf "$REPO.new" mkdir -p "$REPO.new/base" "$REPO.new/extra" "$REPO.new/extra-src" for p in $(sed -n 's/^PKG=\([^ ]*\) \([^ ]*\).*/\1-\2/p' /everest/templates/minimal.template) $EXTRA_PKGS; do r=$(tar -xzOf "$OUT/$p.gpkg" "$p/manifest.gpm.cfg" | sed -n 's/^PKG_REPO *= *"\(.*\)";$/\1/p') case $r in base|extra) cp "$OUT/$p.gpkg" "$OUT/$p.gpkg.sha256" "$REPO.new/$r/" ;; *) echo "[x] $p.gpkg: repository '$r' is not published." >&2; exit 1 ;; esac done /glacier-ng/tests/mkgrcp -o "$REPO.new/extra-src" /everest/recipes/extra-src/*/ >/dev/null # grepo's serial continues from the previous index. for r in base extra extra-src; do [ -f "$REPO/$r/repo.idx" ] && cp "$REPO/$r/repo.idx" "$REPO.new/$r/" /tmp/lg/build/bin/grepo -s "$KEY" -r "$r" "$REPO.new/$r" done chmod -R a+rX "$REPO.new" rm -rf "$REPO" && mv "$REPO.new" "$REPO" give_back "$REPO" } # A throwaway CA and a certificate for pkg.everestlinux.org signed by # it, so the local repo/ can be served over https for tests (the build # container here, QEMU through everest.sh serve). Its key is no secret: # NEVER add ca.pem to anything shipped; tests append it at run time. TESTCA=/everest/testca testca() { [ -f "$TESTCA/server.pem" ] && return 0 mkdir -p "$TESTCA" cd "$TESTCA" openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \ -keyout ca.key -out ca.pem -days 3650 \ -subj "/CN=Everest TEST CA - never trust outside tests" \ -addext "basicConstraints=critical,CA:TRUE" \ -addext "keyUsage=critical,keyCertSign,cRLSign" 2>/dev/null openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \ -keyout server.key -out server.csr -subj "/CN=pkg.everestlinux.org" 2>/dev/null printf 'subjectAltName=DNS:pkg.everestlinux.org\nextendedKeyUsage=serverAuth\nbasicConstraints=CA:FALSE\nkeyUsage=critical,digitalSignature\n' > ext openssl x509 -req -in server.csr -CA ca.pem -CAkey ca.key -CAcreateserial \ -out server.pem -days 3650 -extfile ext 2>/dev/null rm -f server.csr ext ca.srl cd / give_back "$TESTCA" } # Serve /everest/repo as https://pkg.everestlinux.org inside THIS # container (the test CA trusted, the name pointed at 127.0.0.1). serve_local() { [ -f "$REPO/base/repo.idx" ] || { echo "[x] No $REPO: run everest.sh publish first." >&2; exit 1; } testca cat "$TESTCA/ca.pem" >> /etc/ssl/certs/ca-certificates.crt echo "127.0.0.1 pkg.everestlinux.org" >> /etc/hosts (cd "$REPO" && exec openssl s_server -quiet -WWW -accept 443 \ -cert "$TESTCA/server.pem" -key "$TESTCA/server.key" >/dev/null 2>&1) & sleep 1 } # The system is installed by glacier itself: glacier-bootstrap verifies # and resolves templates/minimal.template against pkgs/, then syspkg -R # installs it into $T in one transaction (/glacier/sys, merged /usr, # /etc copied). syspkg refuses to run as root from a tree it doesn't # trust, so glacier-ng is copied to a root-owned /opt/glacier-ng with # the musl-built libraries, and $T must be root-owned (not under /tmp). initramfs() { G=/opt/glacier-ng rm -rf "$G" && cp -a /glacier-ng "$G" mkdir -p "$G/lib/glacier" cp /tmp/lg/build/lib/shared/libglacier_*.so "$G/lib/glacier/" chown -R root:root "$G" && chmod -R go-w "$G" # syspkg -R checks base packages against THIS host's keyring. install -D -m 644 "$TRUST/repos.conf" /etc/glacier/repos.conf install -D -m 644 "$TRUST/keys/$KEY_NAME.pub" "/etc/glacier/keys/$KEY_NAME.pub" # T's repos.conf lists pkg.everestlinux.org, which bootstrap syncs # (syspkg -R T -y): from the local repo/, never the network. serve_local T=/target rm -rf "$T" && mkdir -m 755 "$T" echo y | PATH="$G:$PATH" "$G/glacier-bootstrap" -t \ -d "$OUT" /everest/templates/minimal.template "$T" # The test image reads its repositories from a copy of repo/ at # /srv/everest (file://), so -y/-f/-u work with no network; # `everest.sh boot` can also share repo/ live at the same place # (scripts/vm-testnet.sh mounts it). repos.conf is edited in T, so # it is admin-modified there; the package still ships the https one. mkdir -p -m 755 "$T/srv" cp -a "$REPO" "$T/srv/everest" chown -R root:root "$T/srv/everest" && chmod -R go-w,a+rX "$T/srv/everest" sed 's|url = "https://pkg.everestlinux.org/|url = "file:///srv/everest/|' \ "$T/etc/glacier/repos.conf" > /tmp/repos.conf grep -q 'file:///srv/everest/base' /tmp/repos.conf || { echo "[x] T's repos.conf has no pkg.everestlinux.org url to replace." >&2; exit 1; } install -m 644 /tmp/repos.conf "$T/etc/glacier/repos.conf" mkdir -p /everest/boot # T's links name runtime paths (/glacier/sys/store/...), so resolve # them inside T. chroot "$T" /bin/sh -c 'cat /usr/lib/modules/*/vmlinuz' > /everest/boot/vmlinuz (cd "$T" && find . | cpio -o -H newc 2>/dev/null | gzip -9) > /everest/boot/initramfs.gz # A second archive (the kernel unpacks them in order) holding only # /init, which moves / to a tmpfs (see scripts/live-init.sh). It is # not part of T: an installed system boots from its disk. L=/tmp/live-init rm -rf "$L" && mkdir -m 755 "$L" install -m 755 /everest/scripts/live-init.sh "$L/init" (cd "$L" && echo init | cpio -o -H newc -R 0:0 2>/dev/null | gzip -9) >> /everest/boot/initramfs.gz give_back /everest/boot ls -l /everest/boot } case "${1:-}" in keygen) keygen ;; build) build "${2:?usage: container.sh build PKG}" ;; adopt) adopt "${2:?usage: container.sh adopt DIR}" ;; publish) publish ;; testca) testca ;; initramfs) initramfs ;; *) echo "usage: container.sh keygen | build PKG | adopt DIR | publish | testca | initramfs" >&2; exit 1 ;; esac