#!/usr/bin/env bash

# Remove defaultyes=True from /etc/dnf/dnf.conf on machines Panama configured.
#
# change-settings used to copy a whole dnf.conf over the machine's own, and
# that file set defaultyes=True -- so every `dnf remove`, for every user,
# treated a bare Enter as confirmation. The installer no longer ships the
# file; this repairs the machines that already received it. Only the one
# behavior key is touched: the performance keys it carried are harmless and
# now applied additively by change-settings.

set -euo pipefail

conf=/etc/dnf/dnf.conf

[[ -r "$conf" ]] || exit 0
grep -q '^defaultyes=True$' "$conf" || exit 0

PANAMA_PATH="${PANAMA_PATH:-$HOME/.local/share/Panama}"
sudo_cmd=(sudo)
if [[ -t 0 && -x "$PANAMA_PATH/bin/panama-sudo" ]]; then
    sudo_cmd=(
        "$PANAMA_PATH/bin/panama-sudo" --reason
        "Removing defaultyes=True from dnf.conf, which made every dnf remove treat Enter as yes"
        --
    )
fi

"${sudo_cmd[@]}" sed -i '/^defaultyes=True$/d' "$conf"
echo "Removed defaultyes=True from $conf; dnf prompts default to No again."
