#!/bin/sh
# Copyright © 2006-2018 Canonical Ltd.
# Copyright © 2015-2017 Martin Pitt
# Copyright © 2017 Steve Langasek
# Copyright © 2017-2022 Paul Gevers
# Copyright © 2018 Simon McVittie
# SPDX-License-Identifier: GPL-2.0-or-later

# This script returns the first suite found in apt sources.

# TODO: Debian is moving towards deb822 based sources, this isn't
# supported yet.

# Usage $0

set -eu

SRCS=$(ls /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null || true)
# Deliberately word-splitting $SRCS
# shellcheck disable=SC2086
sed -rn '/^(deb|deb-src) +(\[.*\] *)?(http|https|file):/ { s/\[.*\] +//; s/^[^ ]+ +[^ ]* +([^ ]+) +.*$/\1/p }' $SRCS | head -n1
