#!/usr/bin/env bash set -euo pipefail usage() { echo "Использование: repo_audit.sh [--verbose]" } verbose=0 while [[ $# -gt 0 ]]; do case "$1" in --verbose|-v) verbose=1; shift ;; -h|--help) usage; exit 0 ;; *) echo "Неизвестный аргумент: $1" >&2; usage >&2; exit 2 ;; esac done problems=0 warn() { echo "[WARN] $*" problems=$((problems + 1)) } section() { printf '\n== %s ==\n' "$1" } tmp="$(mktemp)" trap 'rm -f "$tmp"' EXIT if command -v apt-get >/dev/null 2>&1; then section "APT" shopt -s nullglob files=(/etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources) for file in "${files[@]}"; do [[ -f "$file" ]] || continue echo "Файл: $file" if [[ "$file" == *.sources ]]; then awk ' /^[[:space:]]*URIs:/ {line=$0; sub(/^[^:]*:[[:space:]]*/, "", line); print " URI: " line} /^[[:space:]]*Suites:/ {line=$0; sub(/^[^:]*:[[:space:]]*/, "", line); print " Suites: " line} /^[[:space:]]*Enabled:/ {line=$0; sub(/^[^:]*:[[:space:]]*/, "", line); print " Enabled: " line} ' "$file" grep -E '^[[:space:]]*URIs:' "$file" | sed -E 's/^[^:]*:[[:space:]]*//' | tr ' ' '\n' >> "$tmp" || true else while IFS= read -r line; do [[ "$line" == deb* || "$line" == deb-src* ]] || continue uri="$(awk '{for (i = 1; i <= NF; i++) if ($i ~ /^(https?|ftp|file|cdrom):/) {print $i; exit}}' <<< "$line")" if ((verbose == 1)); then echo " $line" elif [[ -n "$uri" ]]; then echo " $uri" fi [[ -n "$uri" ]] && echo "$uri" >> "$tmp" done < <(grep -vE '^[[:space:]]*(#|$)' "$file" || true) fi done if [[ -s "$tmp" ]]; then duplicates="$(sort "$tmp" | uniq -d || true)" if [[ -n "$duplicates" ]]; then warn "Повторяющиеся URI репозиториев:" echo "$duplicates" | sed 's/^/ /' fi if grep -q '^http:' "$tmp"; then warn "Репозитории по HTTP без TLS:" grep '^http:' "$tmp" | sort -u | sed 's/^/ /' fi fi : > "$tmp" fi if command -v dnf >/dev/null 2>&1; then section "DNF" shopt -s nullglob for file in /etc/yum.repos.d/*.repo; do [[ -f "$file" ]] || continue echo "Файл: $file" awk ' /^[[:space:]]*\[/ {section=$0; gsub(/[\[\]]/, "", section); next} /^[[:space:]]*(baseurl|metalink|mirrorlist|enabled|gpgcheck|repo_gpgcheck)[[:space:]]*=/ { line=$0; sub(/^[^=]*=[[:space:]]*/, "", line); print " [" section "] " line } ' "$file" grep -E '^[[:space:]]*(baseurl|metalink|mirrorlist)[[:space:]]*=' "$file" | sed -E 's/^[^=]*=[[:space:]]*//' | tr ' ' '\n' >> "$tmp" || true if grep -qE '^[[:space:]]*gpgcheck[[:space:]]*=[[:space:]]*0' "$file"; then warn "gpgcheck отключён: $file" fi done if [[ -s "$tmp" ]]; then if grep -q '^http:' "$tmp"; then warn "Репозитории DNF по HTTP без TLS:" grep '^http:' "$tmp" | sort -u | sed 's/^/ /' fi fi : > "$tmp" fi if command -v pacman >/dev/null 2>&1; then section "PACMAN" if [[ -f /etc/pacman.conf ]]; then grep -nE '^[[:space:]]*\[|^[[:space:]]*(Server|Include|SigLevel)[[:space:]]*=' /etc/pacman.conf | head -n 80 || true if grep -qE '^[[:space:]]*SigLevel[[:space:]]*=.*Never' /etc/pacman.conf; then warn "SigLevel Never отключает проверку подписей" fi fi if [[ -f /etc/pacman.d/mirrorlist ]]; then echo "Зеркала:" grep -E '^[[:space:]]*Server' /etc/pacman.d/mirrorlist | head -n 10 || true fi fi echo if ((problems > 0)); then echo "Замечаний: $problems" exit 1 fi echo "Замечаний нет."