mirror of
https://github.com/stornic56/debianito-post-install.git
synced 2026-09-14 06:02:35 +00:00
Repos: Empty Sources, Deb822 & Security Fixes
- Enhanced repository detection logic in `modules/repos/repo_detect.sh`. Implemented `has_active_deb_sources()` for content-aware scanning across `sources.list`, `*.list`, and `*.sources` files. Empty or comment-only files are now correctly identified as "none" to trigger bootstrapping. - Enforced Debian 13 (Trixie) specific logic in `detect_repo_format()`. Deb822 format is only applied when `debian.sources` is active; Bookworm and Bullseye systems default strictly to classic sources.list regardless of file presence. - Added state guard against mixed configuration formats (deb822 + classic active simultaneously) with a warning prompt before writing, preventing duplicate entries in `/etc/apt/sources.list`. - Rewrote `_repos_enable_components()` in `modules/repos.sh` to remove early returns when components are already enabled. The script now verifies and ensures security and updates sections exist/were written correctly if missing or different. - Created new `bootstrap_repositories()` function for systems with no active sources. Includes user dialogue for format selection (Trixie) or auto-classic (older versions), backup/restore safety, and cleanup of empty sources.list files post-bootstrap. - Fixed false success reporting in `modules/firmware.sh` and `gaming.sh`. Added pre-checks to ensure APT sources exist before attempting `sed -i` modifications; if sources are missing, the script now triggers a full repository bootstrap instead of silently failing. - Implemented post-write verification in firmware/gaming modules to confirm components were actually added before reporting success to the user. - Generalized backports detection in `modules/utils.sh` (`is_backports_enabled()`) to scan all `*.list` and `*.sources` files rather than relying on fixed canonical filenames. - Corrected test harness variable expansion order and trimmed whitespace from component parsing logic during development verification.
This commit is contained in:
@@ -2,34 +2,76 @@
|
||||
# repo_detect.sh – Detection-only helpers for idempotent repository configuration.
|
||||
# Part A of the two-part architecture. No user dialogs, no writes.
|
||||
|
||||
# Detect the format of the main repo file
|
||||
# Any active (non-commented) source of any format, in any file?
|
||||
# Returns: 0 if at least one active source exists, 1 otherwise
|
||||
has_active_deb_sources() {
|
||||
local f
|
||||
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
|
||||
[ -f "$f" ] || continue
|
||||
grep -qE '^[^#]*\bdeb\b' "$f" 2>/dev/null && return 0
|
||||
done
|
||||
for f in /etc/apt/sources.list.d/*.sources; do
|
||||
[ -f "$f" ] || continue
|
||||
grep -qE '^Types:.*\bdeb\b' "$f" 2>/dev/null && \
|
||||
grep -qE '^URIs:' "$f" 2>/dev/null && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Detect the format of the main repo file (content-aware).
|
||||
# DEB822 is only valid on Debian 13 (Trixie); Debian 11/12 are classic-only.
|
||||
# Returns: "deb822", "classic", or "none"
|
||||
detect_repo_format() {
|
||||
if [ -f /etc/apt/sources.list.d/debian.sources ]; then
|
||||
if [ "$DEBIAN_VERSION" = "13" ] && [ -f /etc/apt/sources.list.d/debian.sources ] && \
|
||||
grep -qE '^Types:.*\bdeb\b' /etc/apt/sources.list.d/debian.sources 2>/dev/null; then
|
||||
echo "deb822"
|
||||
elif [ -f /etc/apt/sources.list ]; then
|
||||
elif [ -f /etc/apt/sources.list ] && grep -qE '^[^#]*\bdeb\b' /etc/apt/sources.list 2>/dev/null; then
|
||||
echo "classic"
|
||||
else
|
||||
echo "none"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check whether backports are currently enabled (any format)
|
||||
# Detect the components currently active in the main repo file
|
||||
# Returns: components list (e.g. "main contrib non-free non-free-firmware")
|
||||
detect_active_components() {
|
||||
if [ "$DEBIAN_VERSION" = "13" ] && [ -f /etc/apt/sources.list.d/debian.sources ]; then
|
||||
local comps
|
||||
comps=$(grep "^Components:" /etc/apt/sources.list.d/debian.sources 2>/dev/null | head -1 | cut -d: -f2- | sed 's/^[[:space:]]*//')
|
||||
if [ -n "$comps" ]; then
|
||||
echo "$comps"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if [ -f /etc/apt/sources.list ]; then
|
||||
local comps
|
||||
comps=$(grep "^[^#]*deb .* main" /etc/apt/sources.list 2>/dev/null | head -1 | sed 's/.*main\s*//')
|
||||
if [ -n "$comps" ]; then
|
||||
echo "main $comps"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if [ "$DEBIAN_VERSION" = "11" ]; then
|
||||
echo "main contrib non-free"
|
||||
else
|
||||
echo "main contrib non-free non-free-firmware"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check whether backports are currently enabled (any format, any file)
|
||||
# Returns: 0 if enabled, 1 otherwise
|
||||
detect_backports_status() {
|
||||
local codename="$1"
|
||||
|
||||
if [ -f /etc/apt/sources.list.d/debian.sources ]; then
|
||||
if [ "$DEBIAN_VERSION" = "13" ] && [ -f /etc/apt/sources.list.d/debian.sources ]; then
|
||||
grep -qE "^Suites:.*${codename}-backports" /etc/apt/sources.list.d/debian.sources 2>/dev/null && return 0
|
||||
fi
|
||||
if [ -f /etc/apt/sources.list ]; then
|
||||
grep -qE "^[^#]*${codename}-backports" /etc/apt/sources.list 2>/dev/null && return 0
|
||||
fi
|
||||
if [ -f /etc/apt/sources.list.d/debian-backports.sources ]; then
|
||||
grep -qE "^Suites:.*${codename}-backports" /etc/apt/sources.list.d/debian-backports.sources 2>/dev/null && return 0
|
||||
fi
|
||||
if [ -f /etc/apt/sources.list.d/debian-backports.list ]; then
|
||||
grep -qE "^[^#]*${codename}-backports" /etc/apt/sources.list.d/debian-backports.list 2>/dev/null && return 0
|
||||
if [ -d /etc/apt/sources.list.d ]; then
|
||||
grep -qrE "^Suites:.*${codename}-backports" /etc/apt/sources.list.d/*.sources 2>/dev/null && return 0
|
||||
grep -qrE "^[^#]*${codename}-backports" /etc/apt/sources.list.d/*.list 2>/dev/null && return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
@@ -44,18 +86,26 @@ detect_backports_status() {
|
||||
detect_backports_location() {
|
||||
local codename="$1"
|
||||
|
||||
if [ -f /etc/apt/sources.list.d/debian-backports.sources ] && \
|
||||
if [ "$DEBIAN_VERSION" = "13" ] && [ -f /etc/apt/sources.list.d/debian-backports.sources ] && \
|
||||
grep -qE "^Suites:.*${codename}-backports" /etc/apt/sources.list.d/debian-backports.sources 2>/dev/null; then
|
||||
echo "standalone-deb822"
|
||||
elif [ -f /etc/apt/sources.list.d/debian-backports.list ] && \
|
||||
grep -qE "^[^#]*${codename}-backports" /etc/apt/sources.list.d/debian-backports.list 2>/dev/null; then
|
||||
echo "standalone-classic"
|
||||
elif [ -f /etc/apt/sources.list.d/debian.sources ] && \
|
||||
elif [ "$DEBIAN_VERSION" = "13" ] && [ -f /etc/apt/sources.list.d/debian.sources ] && \
|
||||
grep -qE "^Suites:.*${codename}-backports" /etc/apt/sources.list.d/debian.sources 2>/dev/null; then
|
||||
echo "embedded-deb822"
|
||||
elif [ -f /etc/apt/sources.list ] && \
|
||||
grep -qE "^[^#]*${codename}-backports" /etc/apt/sources.list 2>/dev/null; then
|
||||
echo "embedded-classic"
|
||||
elif [ -d /etc/apt/sources.list.d ]; then
|
||||
if grep -qrE "^Suites:.*${codename}-backports" /etc/apt/sources.list.d/*.sources 2>/dev/null; then
|
||||
echo "embedded-deb822"
|
||||
elif grep -qrE "^[^#]*${codename}-backports" /etc/apt/sources.list.d/*.list 2>/dev/null; then
|
||||
echo "embedded-classic"
|
||||
else
|
||||
echo "none"
|
||||
fi
|
||||
else
|
||||
echo "none"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user