#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later

# This script returns the list of configured sources in deb822-style source
# lists (/etc/apt/sources.list.d/*.sources). Sources are not stripped out of
# comments, extra blank lines or similar: the output of this script is meant to
# be consumed by a deb822 parser that is able to correctly handle those.
# See sources.list(5) for more information on the APT source list formats.
#
# This script takes no arguments.

set -eu

# Awk concatenates files making sure stanzas from separate files are separated
# by a blank line, even if there are no newlines at EOF in the .sources files.
if [ -d /etc/apt/sources.list.d ]; then
    find /etc/apt/sources.list.d -maxdepth 1 -type f -regex '.*/[a-zA-Z0-9_.-]+\.sources' -print0 \
        | LC_ALL=C sort --zero-terminated \
        | xargs -0 --no-run-if-empty -- awk 'FNR == 1 && NR != 1 { print "" } { print }'
fi
