#!/usr/bin/env bash
# deps-only.sh — install only dependencies of a fixed package (never the package itself).
# Set your target package here:
pkg="lightdm"   # e.g. "lightdm", "gedit", "hexchat", ...

set -Eeuo pipefail
sudo -v

# Build the would-be dependency list (excluding the package itself)
mapfile -t deps < <(
  LANG=C sudo apt-get -s install --no-install-recommends "$pkg" \
    | grep -Po '^Inst \K[^ ]+' \
    | grep -vE "^${pkg}(:[^ ]+)?$" \
    | sort -u
)

if ((${#deps[@]}==0)); then
  echo "No new dependencies required."
  exit 0
fi

echo "These ${#deps[@]} dependencies will be installed (without ${pkg}):"
printf '  %s\n' "${deps[@]}"

# Script-level confirmation (default = No)
read -r -p "Proceed to install? [y/N] " ans
case "$ans" in
  [yY]|[yY][eE][sS])
    # Install after confirmation.
    # We explicitly unset DEBIAN_FRONTEND if it was noninteractive somewhere.
    sudo env -u DEBIAN_FRONTEND apt-get --assume-yes install --no-install-recommends "${deps[@]}"
    ;;
  *)
    echo "Aborted."
    exit 1
    ;;
esac
