mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-08-01 05:16:19 +00:00
new version 1.2.4
This commit is contained in:
@@ -85,87 +85,167 @@ lvm_repair_check() {
|
||||
|
||||
cleanup_duplicate_repos_pve9() {
|
||||
msg_info "$(translate "Cleaning up duplicate repositories...")"
|
||||
|
||||
local sources_file="/etc/apt/sources.list"
|
||||
local temp_file=$(mktemp)
|
||||
local cleaned_count=0
|
||||
declare -A seen_repos
|
||||
|
||||
if [ ! -s "$sources_file" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
|
||||
echo "$line" >> "$temp_file"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ "$line" =~ ^deb ]]; then
|
||||
read -r _ url dist components <<< "$line"
|
||||
local key="${url}_${dist}"
|
||||
if [[ -v "seen_repos[$key]" ]]; then
|
||||
echo "# $line" >> "$temp_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
msg_info "$(translate "Commented duplicate: $url $dist")"
|
||||
local sources_file="/etc/apt/sources.list"
|
||||
local cleaned_count=0
|
||||
|
||||
# Helper: extract a DEB822 field's value from a .sources file. Handles
|
||||
# both `Field: value` and folded continuations. Returns the FIRST value
|
||||
# only (URIs / Suites / Components with multiple entries are read as a
|
||||
# single whitespace-separated string that callers split themselves).
|
||||
_deb822_get() {
|
||||
local file="$1" field="$2"
|
||||
[[ -f "$file" ]] || return 1
|
||||
awk -v F="$field" '
|
||||
BEGIN{ IGNORECASE=1 }
|
||||
/^[[:space:]]*$/{ next }
|
||||
/^[^[:space:]]/{
|
||||
if (match($0, "^"F"[[:space:]]*:[[:space:]]*")) {
|
||||
print substr($0, RSTART+RLENGTH)
|
||||
exit
|
||||
}
|
||||
}
|
||||
' "$file"
|
||||
}
|
||||
|
||||
# Helper: back up a file once before modifying, so an accidental
|
||||
# comment-out is always recoverable next to the original.
|
||||
_backup_once() {
|
||||
local file="$1"
|
||||
[[ -f "$file" ]] || return 0
|
||||
local ts backup
|
||||
ts=$(date +%Y%m%d_%H%M%S)
|
||||
backup="${file}.proxmenux-backup.${ts}"
|
||||
[[ -f "$backup" ]] || cp -a "$file" "$backup"
|
||||
}
|
||||
|
||||
# ── Phase 1 — comment intra-file duplicates in sources.list by URL+Suite ──
|
||||
if [ -s "$sources_file" ]; then
|
||||
local temp_file
|
||||
temp_file=$(mktemp)
|
||||
declare -A seen_repos
|
||||
local file_changed=0
|
||||
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
|
||||
echo "$line" >> "$temp_file"
|
||||
continue
|
||||
fi
|
||||
if [[ "$line" =~ ^deb ]]; then
|
||||
read -r _ url dist components <<< "$line"
|
||||
local key="${url}_${dist}"
|
||||
# Portable "is this associative-array key set?" — `[[ -v arr[key] ]]`
|
||||
# is only reliable in bash 4.4+; `${var+set}` works everywhere.
|
||||
if [[ -n "${seen_repos[$key]+set}" ]]; then
|
||||
echo "# $line" >> "$temp_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
file_changed=1
|
||||
msg_info "$(translate "Commented duplicate: $url $dist")"
|
||||
else
|
||||
echo "$line" >> "$temp_file"
|
||||
seen_repos[$key]="$components"
|
||||
fi
|
||||
else
|
||||
echo "$line" >> "$temp_file"
|
||||
seen_repos[$key]="$components"
|
||||
fi
|
||||
done < "$sources_file"
|
||||
|
||||
if [[ "$file_changed" -eq 1 ]]; then
|
||||
_backup_once "$sources_file"
|
||||
mv "$temp_file" "$sources_file"
|
||||
chmod 644 "$sources_file"
|
||||
else
|
||||
echo "$line" >> "$temp_file"
|
||||
fi
|
||||
done < "$sources_file"
|
||||
|
||||
mv "$temp_file" "$sources_file"
|
||||
chmod 644 "$sources_file"
|
||||
|
||||
|
||||
if [ -f "/etc/apt/sources.list.d/proxmox.sources" ]; then
|
||||
|
||||
|
||||
|
||||
if grep -q "^deb.*download\.proxmox\.com" "$sources_file"; then
|
||||
sed -i '/^deb.*download\.proxmox\.com/s/^/# /' "$sources_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
fi
|
||||
|
||||
for list_file in /etc/apt/sources.list.d/pve-*.list; do
|
||||
if [ -f "$list_file" ] && [[ "$list_file" != "/etc/apt/sources.list.d/pve-enterprise.list" ]]; then
|
||||
if grep -q "^deb" "$list_file"; then
|
||||
sed -i 's/^deb/# deb/g' "$list_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -f "/etc/apt/sources.list.d/debian.sources" ]; then
|
||||
|
||||
if grep -q "^deb.*deb\.debian\.org" "$sources_file"; then
|
||||
sed -i '/^deb.*deb\.debian\.org/s/^/# /' "$sources_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
|
||||
fi
|
||||
|
||||
if grep -q "^deb.*security\.debian\.org" "$sources_file"; then
|
||||
sed -i '/^deb.*security\.debian\.org/s/^/# /' "$sources_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
|
||||
fi
|
||||
rm -f "$temp_file"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# ── Phase 2 — comment lines duplicating what proxmox.sources already declares ──
|
||||
# Comparison is EXACT on URL + Suite + at least one Component match, so a
|
||||
# legitimate custom repo the user added under `download.proxmox.com` (e.g.
|
||||
# /debian/pbs, /debian/ceph-squid, or the same URL pinned to a different
|
||||
# suite) is preserved untouched.
|
||||
if [ -f "/etc/apt/sources.list.d/proxmox.sources" ]; then
|
||||
local pmx_uri pmx_suite pmx_comps
|
||||
pmx_uri=$(_deb822_get /etc/apt/sources.list.d/proxmox.sources URIs)
|
||||
pmx_suite=$(_deb822_get /etc/apt/sources.list.d/proxmox.sources Suites)
|
||||
pmx_comps=$(_deb822_get /etc/apt/sources.list.d/proxmox.sources Components)
|
||||
|
||||
_match_and_comment() {
|
||||
local target_file="$1" uri="$2" suite="$3" comps="$4"
|
||||
[[ -f "$target_file" ]] || return 0
|
||||
[[ -n "$uri" && -n "$suite" && -n "$comps" ]] || return 0
|
||||
local base_uri="${uri#http://}"
|
||||
base_uri="${base_uri#https://}"
|
||||
base_uri="${base_uri%/}"
|
||||
local first_comp
|
||||
first_comp=$(awk '{print $1}' <<< "$comps")
|
||||
local matched=0
|
||||
while IFS= read -r ln; do
|
||||
[[ "$ln" =~ ^[[:space:]]*# ]] && continue
|
||||
[[ "$ln" =~ ^deb ]] || continue
|
||||
read -r _ line_url line_suite line_comps <<< "$ln"
|
||||
local ln_base="${line_url#http://}"
|
||||
ln_base="${ln_base#https://}"
|
||||
ln_base="${ln_base%/}"
|
||||
[[ "$ln_base" == "$base_uri" ]] || continue
|
||||
[[ "$line_suite" == "$suite" ]] || continue
|
||||
[[ " $line_comps " == *" $first_comp "* ]] || continue
|
||||
matched=1
|
||||
break
|
||||
done < "$target_file"
|
||||
if [[ "$matched" -eq 1 ]]; then
|
||||
_backup_once "$target_file"
|
||||
# Anchored sed: reconstruct the exact deb prefix to avoid
|
||||
# eating unrelated lines. Escape URL for regex safety.
|
||||
local esc_uri esc_suite esc_comp
|
||||
esc_uri=$(printf '%s' "$uri" | sed 's/[][\.^$*/]/\\&/g')
|
||||
esc_suite=$(printf '%s' "$suite" | sed 's/[][\.^$*/]/\\&/g')
|
||||
esc_comp=$(printf '%s' "$first_comp" | sed 's/[][\.^$*/]/\\&/g')
|
||||
sed -i -E "/^deb[[:space:]]+${esc_uri}[[:space:]]+${esc_suite}[[:space:]]+.*(^| )${esc_comp}( |$)/s/^/# /" "$target_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
_match_and_comment "$sources_file" "$pmx_uri" "$pmx_suite" "$pmx_comps"
|
||||
|
||||
# Only walk a fixed allowlist of known-legacy PVE list files. Any
|
||||
# other pve-*.list on disk is assumed to be user-authored (custom
|
||||
# mirror, backports, staging) and left alone.
|
||||
local legacy_pve_lists=(
|
||||
/etc/apt/sources.list.d/pve-public-repo.list
|
||||
/etc/apt/sources.list.d/pve-install-repo.list
|
||||
/etc/apt/sources.list.d/pve-no-subscription.list
|
||||
)
|
||||
for legacy in "${legacy_pve_lists[@]}"; do
|
||||
_match_and_comment "$legacy" "$pmx_uri" "$pmx_suite" "$pmx_comps"
|
||||
done
|
||||
|
||||
# Same exact-match approach for debian.sources vs sources.list.
|
||||
if [ -f "/etc/apt/sources.list.d/debian.sources" ]; then
|
||||
local dbn_uri dbn_suite dbn_comps
|
||||
dbn_uri=$(_deb822_get /etc/apt/sources.list.d/debian.sources URIs)
|
||||
dbn_suite=$(_deb822_get /etc/apt/sources.list.d/debian.sources Suites)
|
||||
dbn_comps=$(_deb822_get /etc/apt/sources.list.d/debian.sources Components)
|
||||
# `Suites` in debian.sources holds multiple ("trixie trixie-updates"),
|
||||
# walk each so both duplicates get commented if present.
|
||||
for suite_iter in $dbn_suite; do
|
||||
_match_and_comment "$sources_file" "$dbn_uri" "$suite_iter" "$dbn_comps"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# ── Phase 3 — remove ONLY the well-known legacy files, and only when the
|
||||
# modern replacement already exists ──
|
||||
if [ -f "/etc/apt/sources.list.d/proxmox.sources" ]; then
|
||||
for old_file in /etc/apt/sources.list.d/pve-public-repo.list /etc/apt/sources.list.d/pve-install-repo.list; do
|
||||
if [ -f "$old_file" ]; then
|
||||
_backup_once "$old_file"
|
||||
rm -f "$old_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
if [ $cleaned_count -gt 0 ]; then
|
||||
msg_ok "$(translate "Cleaned up $cleaned_count duplicate/old repositories")"
|
||||
apt-get update > /dev/null 2>&1 || true
|
||||
@@ -193,7 +273,7 @@ cleanup_duplicate_repos_pve9_() {
|
||||
if [[ "$line" =~ ^deb ]]; then
|
||||
read -r _ url dist components <<< "$line"
|
||||
local key="${url}_${dist}"
|
||||
if [[ -v "seen_repos[$key]" ]]; then
|
||||
if [[ -n "${seen_repos[$key]+set}" ]]; then
|
||||
echo "# $line" >> "$temp_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
else
|
||||
@@ -276,7 +356,7 @@ cleanup_duplicate_repos_pve8() {
|
||||
if [[ "$line" =~ ^[[:space:]]*deb ]]; then
|
||||
read -r _ url dist components <<< "$line"
|
||||
local key="${url}_${dist}"
|
||||
if [[ -v "seen_repos[$key]" ]]; then
|
||||
if [[ -n "${seen_repos[$key]+set}" ]]; then
|
||||
echo "# $line" >> "$temp_file"
|
||||
cleaned_count=$((cleaned_count + 1))
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user