FROM ubuntu:22.04

# Minimal image for safe simulation of apt installs.
RUN apt-get update && apt-get install -y --no-install-recommends \
    bash wget tar curl gnupg ca-certificates apt-utils apt coreutils file procps && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# sudo wrapper: simulate apt installs and avoid making changes to the image
RUN cat > /usr/local/bin/sudo <<'EOF'
#!/bin/sh
# sudo wrapper for simulation:
# - simulate installs with `apt-get -s install ...`
# - run `apt-get update` quietly (needed so apt -s has metadata)
# - otherwise echo the command (no-op)
cmd="$1"
arg2="${2:-}"
if [ "$cmd" = "apt" ] || [ "$cmd" = "apt-get" ]; then
  if [ "$arg2" = "install" ]; then
    shift 2
    echo "[sudo-wrapper] simulating: apt-get -s install $@"
    apt-get -s install "$@"
    exit $?
  elif [ "$arg2" = "update" ]; then
    # do not run update at runtime (may require extra privileges); simulate instead
    echo "[sudo-wrapper] simulating: apt-get update (no-op in container)"
    exit 0
  else
    echo "[sudo-wrapper] would run: $@"
    exit 0
  fi
else
  echo "[sudo-wrapper] would run: $@"
  exit 0
fi
EOF
RUN chmod +x /usr/local/bin/sudo

ENV PATH=/usr/local/bin:$PATH

WORKDIR /workspace
ENTRYPOINT ["/bin/bash"]
