#!/bin/sh
# devplace aptroot: lets pravda (uid 1000) run apt / apt-get / dpkg with full
# package-manager power, without real root and without sudo. It runs the real
# tool under fakeroot, so every chown-to-root dpkg performs is virtualized and
# every file written to disk stays owned by pravda (uid 1000). Combined with
# pravda owning the system trees, `apt install <pkg>` just works, and nothing
# can ever create a root-owned file on the host bind mount.

_dp_tool="$(basename "$0")"
_dp_real="/usr/bin/${_dp_tool}"

if [ ! -x "$_dp_real" ]; then
    echo "aptroot: real ${_dp_tool} not found at ${_dp_real}" >&2
    exit 127
fi

case "$_dp_tool" in
    apt|apt-get)
        exec fakeroot "$_dp_real" \
            -o APT::Sandbox::User=root \
            -o Dpkg::Use-Pty=0 \
            "$@"
        ;;
    *)
        exec fakeroot "$_dp_real" "$@"
        ;;
esac
