zc2 0.0.52

P2P compute broker with yen-denominated billing, WAL, and broker mesh support
#!/bin/sh
# zakuro .deb postinst (zc#636): make the sandbox work without the owner
# touching a terminal. Incus (the LXC sandbox, zc#512) is initialised once and
# the installing user joins incus-admin; on hosts where the Depends resolved
# to Docker instead (Debian 12 without backports), they join docker.
#
# Never fails the install: a sandbox that is still not usable shows on the
# app's Check screen, and zc falls back to the next backend.
set -u

[ "${1:-}" = configure ] || exit 0

warn() { echo "zakuro: $*" >&2; }

# The person installing: sudo, then pkexec (GUI software installers).
user="${SUDO_USER:-}"
if [ -z "$user" ] && [ -n "${PKEXEC_UID:-}" ]; then
  user="$(id -nu "$PKEXEC_UID" 2>/dev/null || true)"
fi
[ "$user" = root ] && user=""

# One group, the least access the sandbox needs: incus-admin when Incus is
# here (zc then runs every tier in LXC), docker only when it is not.
group=docker
if command -v incus >/dev/null 2>&1; then
  group=incus-admin
  # Initialise only a daemon with no storage pool yet: a second init on a
  # configured Incus would fail or add a second pool.
  if pools="$(timeout 60 incus storage list --format csv 2>/dev/null)"; then
    if [ -z "$pools" ]; then
      timeout 120 incus admin init --minimal \
        || warn "incus admin init failed; run: sudo incus admin init --minimal"
    fi
  else
    warn "the incus daemon is not reachable; run: sudo incus admin init --minimal"
  fi
fi

if getent group "$group" >/dev/null 2>&1; then
  if [ -z "$user" ]; then
    warn "add yourself to the $group group: sudo usermod -aG $group \$USER (then log out and back in)"
  elif ! id -nG "$user" 2>/dev/null | tr ' ' '\n' | grep -qx "$group"; then
    usermod -aG "$group" "$user" \
      && echo "zakuro: added $user to $group; log out and back in for the sandbox to work" \
      || warn "could not add $user to $group"
  fi
fi

exit 0