#!/bin/sh
# Makes a release tarball from cont8nuum installed in /opt/cont8nuum, on
# the distribution it was built on (in CI: Ubuntu 26.04), into OUTDIR:
#
# ./build.sh --prefix /opt/cont8nuum --apps all \
# "-Dc_link_args=-Wl,-rpath,/opt/cont8nuum/lib/$(cc -print-multiarch)"
# packaging/release/make-tarball.sh OUTDIR
#
# The name says what it was built on, cont8nuum-VERSION-DISTRO-ARCH (VERSION
# is the tag at this commit, or git-COMMIT). It unpacks to /opt/cont8nuum
# and runs from there: the paths are built in, the rpath finds our
# libraries, and the libraries the distribution lacks (those this machine
# has in /usr/local: wlroots, gexiv2) come along. Everything else comes from
# the distribution's packages, listed in PACKAGES.txt: the ones in
# packaging/distro/DISTRO.txt, checked against its archive, and the
# packages of every library the programs load. Needs root (it moves the
# bundled libraries out of /usr/local to prove they aren't used from there),
# so it's for a throwaway container.
set -eu
top=$(cd "$(dirname "$0")/../.." && pwd)
p=/opt/cont8nuum
out=${1:?usage: make-tarball.sh OUTDIR}
[ "$(id -u)" = 0 ] || { echo "make-tarball.sh: run it in a container, as root" >&2; exit 1; }
[ -x "$p/bin/c8" ] || { echo "make-tarball.sh: nothing in $p" >&2; exit 1; }
. /etc/os-release
distro=$ID-$VERSION_ID
list=$top/packaging/distro/$distro.txt
[ -f "$list" ] || { echo "make-tarball.sh: no $list: say what $PRETTY_NAME needs first" >&2; exit 1; }
arch=$(uname -m)
multiarch=$(cc -print-multiarch)
commit=${TACK_COMMIT:-$(git -C "$top" rev-parse HEAD)}
version=$(git -C "$top" describe --tags --exact-match "$commit" 2>/dev/null ||
echo "git-$(echo "$commit" | cut -c1-12)")
name=cont8nuum-$version-$distro-$arch
glibc=$(ldd --version | head -1 | awk '{print $NF}')
echo "== $name (glibc $glibc)"
# Made ready in place: the rpath points at /opt/cont8nuum, so that's where
# it has to be tried. Notes go to $stage.
stage=$(mktemp -d)
r=$p
lib=$r/lib/$multiarch
# What only building needs
rm -rf "$r/include" "$lib/pkgconfig" "$r/share/pkgconfig"
find "$r" -name '*.a' -delete
# The session's command starts from /opt/cont8nuum, and the files setup
# puts outside it, as a /usr install would have them
install -D -m 0755 "$top/packaging/release/cont8nuum-session" "$r/libexec/cont8nuum-session"
sed -i "s|^Exec=.*|Exec=$p/libexec/cont8nuum-session|" "$r/share/wayland-sessions/cont8nuum.desktop"
install -m 0755 "$top/packaging/release/setup" "$r/setup"
install -D -m 0755 "$top/desktop/shell/data/askpass/sudo-askpass.sh" "$r/libexec/cont8nuum/sudo-askpass.sh"
sys=$r/share/cont8nuum/system
install -D -m 0644 "$top/desktop/shell/data/pam/c8-lock" "$sys/pam.d/c8-lock"
install -D -m 0644 "$top/apps/files/data/c8.portal" "$sys/portals/c8.portal"
mkdir -p "$sys/polkit" "$sys/profile.d"
sed "s|@helper@|$p/libexec/c8-login-picture|" \
"$top/desktop/shell/data/polkit/org.cont8nuum.login-picture.policy.in" \
> "$sys/polkit/org.cont8nuum.login-picture.policy"
sed "s|@ASKPASS@|$p/bin/c8-askpass|g" "$top/desktop/shell/data/askpass/c8-askpass.sh.in" \
> "$sys/profile.d/c8-askpass.sh"
for f in "$r/share/wayland-sessions/cont8nuum.desktop" "$r/lib/systemd/user/cont8nuum-session.target" \
"$r/etc/xdg/xdg-desktop-portal-wlr/cont8nuum" "$r/lib/udev/rules.d/70-cont8nuum-xreal.rules" \
"$r/share/xdg-desktop-portal/cont8nuum-portals.conf" "$r/share/fonts/selawik"; do
[ -e "$f" ] || { echo "make-tarball.sh: setup needs $f, which isn't there" >&2; exit 1; }
done
elves() { # every ELF file in the tarball
find "$r" -type f | while read -r f; do
head -c 4 "$f" | grep -q 'ELF' && echo "$f"
done
}
# Bundle what the distribution lacks: whatever the programs load from /usr/local
bundled=
for f in $(elves); do
ldd "$f" 2>/dev/null | awk '$3 ~ /^\/usr\/local\// {print $3}'
done | sort -u > "$stage/local"
while read -r l; do
real=$(readlink -f "$l")
cp -a "$real" "$lib/"
# the name it's loaded by, if that isn't the file itself (wlroots')
if [ "$(basename "$real")" != "$(basename "$l")" ]; then
ln -sfn "$(basename "$real")" "$lib/$(basename "$l")"
fi
bundled="$bundled $(basename "$l")"
done < "$stage/local"
echo "== bundled:${bundled:- nothing}"
# Prove it: with /usr/local's copies gone, everything must still load,
# and nothing from outside the tarball but the distribution's own
while read -r l; do
mv "$(readlink -f "$l")" "$stage/"
rm -f "$l"
done < "$stage/local"
ldconfig
: > "$stage/libs"
for f in $(elves); do
out_ldd=$(ldd "$f" 2>&1) || continue # not a dynamic executable or library
if echo "$out_ldd" | grep -q 'not found'; then
echo "make-tarball.sh: $f can't find: $(echo "$out_ldd" | grep 'not found' | awk '{print $1}' | tr '\n' ' ')" >&2
missing=yes
fi
echo "$out_ldd" | awk '$2 == "=>" && $3 ~ /^\// {print $3}' >> "$stage/libs"
done
[ -z "${missing:-}" ] || exit 1
# Every library the programs load from outside /opt/cont8nuum, as packages
sort -u "$stage/libs" | grep -v "^$p/" > "$stage/ext" || true
while read -r l; do
pkg=
for c in "$l" "$(readlink -f "$l")" "/usr${l#/usr}" "${l#/usr}"; do
pkg=$(dpkg -S "$c" 2>/dev/null | head -1 | cut -d: -f1) && [ -n "$pkg" ] && break
done
[ -n "$pkg" ] || { echo "make-tarball.sh: no package has $l" >&2; exit 1; }
echo "$pkg"
done < "$stage/ext" > "$stage/libpkgs.all"
sort -u "$stage/libpkgs.all" > "$stage/libpkgs"
# The packages listed by hand must exist in the archive
apt-get update -qq
wanted=$(sed 's/#.*//' "$list" | awk 'NF == 2 {print $2}')
for pkg in $wanted; do
apt-cache show --no-all-versions "$pkg" >/dev/null 2>&1 ||
{ echo "make-tarball.sh: $PRETTY_NAME has no package $pkg ($list)" >&2; exit 1; }
done
required=$( (sed 's/#.*//' "$list" | awk '$1 == "required" {print $2}'; cat "$stage/libpkgs") | sort -u | tr '\n' ' ')
recommended=$(sed 's/#.*//' "$list" | awk '$1 == "recommended" {print $2}' | sort -u | tr '\n' ' ')
{
echo "# What $name needs from $PRETTY_NAME's packages."
echo "# required: the programs' libraries and what the desktop runs"
echo "# recommended: optional parts"
for x in $required; do echo "required $x"; done
for x in $recommended; do echo "recommended $x"; done
} > "$r/PACKAGES.txt"
cat > "$r/README.txt" <<EOF
cont8nuum $version for $PRETTY_NAME, $arch
==========================================
A Metro-style Wayland desktop. This build was made on $PRETTY_NAME
(glibc $glibc) and uses that distribution's packages: on another
distribution, or another version, it may not run. Its source is at
https://knot.lowtide.sbs/lowtide.sbs/cont8nuum (commit $commit).
It lives in /opt/cont8nuum. To install it:
sudo tar -C /opt -xf $name.tar.gz
sudo apt install \$(awk '\$1 == "required" {print \$2}' /opt/cont8nuum/PACKAGES.txt)
sudo /opt/cont8nuum/setup
Then log out and pick cont8nuum on the sign-in screen. PACKAGES.txt also
lists the recommended packages, for the optional parts. Not in this
build yet: VR games in XR glasses (Monado), and the wallet (oo7).
Bundled, because $PRETTY_NAME doesn't have these versions:$bundled
To update, unpack the new tarball over the old one and run setup again.
To remove it: sudo /opt/cont8nuum/setup --remove, then sudo rm -r /opt/cont8nuum
cont8nuum is by lowtide, CC0 1.0 (public domain); third-party parts keep
their licences, listed in the source's README.md.
EOF
mkdir -p "$out"
tar -C /opt --owner=0 --group=0 --numeric-owner --sort=name -czf "$out/$name.tar.gz" cont8nuum
(cd "$out" && sha256sum "$name.tar.gz" > "$name.tar.gz.sha256")
ls -l "$out"
echo "== required: $required"
rm -rf "$stage"