mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-08-14 08:52:22 +00:00
Update common-functions.sh
This commit is contained in:
parent
3598906cbd
commit
894a23d701
@ -82,30 +82,30 @@ lvm_repair_check() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cleanup_duplicate_repos_pve9_() {
|
|
||||||
|
|
||||||
|
cleanup_duplicate_repos_pve9() {
|
||||||
msg_info "$(translate "Cleaning up duplicate repositories...")"
|
msg_info "$(translate "Cleaning up duplicate repositories...")"
|
||||||
|
|
||||||
local cleaned_count=0
|
|
||||||
local sources_file="/etc/apt/sources.list"
|
local sources_file="/etc/apt/sources.list"
|
||||||
|
local temp_file=$(mktemp)
|
||||||
|
local cleaned_count=0
|
||||||
if [[ -f "$sources_file" ]]; then
|
|
||||||
local temp_file
|
|
||||||
temp_file=$(mktemp)
|
|
||||||
declare -A seen_repos
|
declare -A seen_repos
|
||||||
|
|
||||||
|
|
||||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
|
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
|
||||||
echo "$line" >> "$temp_file"
|
echo "$line" >> "$temp_file"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$line" =~ ^[[:space:]]*deb ]]; then
|
if [[ "$line" =~ ^deb ]]; then
|
||||||
read -r _ url dist components <<< "$line"
|
read -r _ url dist components <<< "$line"
|
||||||
local key="${url}_${dist}"
|
local key="${url}_${dist}"
|
||||||
if [[ -v "seen_repos[$key]" ]]; then
|
if [[ -v "seen_repos[$key]" ]]; then
|
||||||
echo "# $line" >> "$temp_file"
|
echo "# $line" >> "$temp_file"
|
||||||
cleaned_count=$((cleaned_count + 1))
|
cleaned_count=$((cleaned_count + 1))
|
||||||
|
msg_info "$(translate "Commented duplicate: $url $dist")"
|
||||||
else
|
else
|
||||||
echo "$line" >> "$temp_file"
|
echo "$line" >> "$temp_file"
|
||||||
seen_repos[$key]="$components"
|
seen_repos[$key]="$components"
|
||||||
@ -117,94 +117,77 @@ cleanup_duplicate_repos_pve9_() {
|
|||||||
|
|
||||||
mv "$temp_file" "$sources_file"
|
mv "$temp_file" "$sources_file"
|
||||||
chmod 644 "$sources_file"
|
chmod 644 "$sources_file"
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
local legacy_list_files=(
|
if [ -f "/etc/apt/sources.list.d/proxmox.sources" ]; then
|
||||||
/etc/apt/sources.list.d/debian.list
|
|
||||||
/etc/apt/sources.list.d/pve-public-repo.list
|
|
||||||
/etc/apt/sources.list.d/pve-install-repo.list
|
|
||||||
/etc/apt/sources.list.d/proxmox.list
|
|
||||||
/etc/apt/sources.list.d/ceph.list
|
|
||||||
)
|
|
||||||
|
|
||||||
for file in "${legacy_list_files[@]}"; do
|
|
||||||
if [[ -f "$file" ]]; then
|
|
||||||
msg_info "$(translate "Removing old repository file: $(basename "$file")")"
|
if grep -q "^deb.*download\.proxmox\.com" "$sources_file"; then
|
||||||
rm -f "$file"
|
sed -i '/^deb.*download\.proxmox\.com/s/^/# /' "$sources_file"
|
||||||
cleaned_count=$((cleaned_count + 1))
|
cleaned_count=$((cleaned_count + 1))
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
|
for list_file in /etc/apt/sources.list.d/pve-*.list; do
|
||||||
local list_sources_pairs=(
|
if [ -f "$list_file" ] && [[ "$list_file" != "/etc/apt/sources.list.d/pve-enterprise.list" ]]; then
|
||||||
"pve-enterprise"
|
if grep -q "^deb" "$list_file"; then
|
||||||
"ceph"
|
sed -i 's/^deb/# deb/g' "$list_file"
|
||||||
"proxmox"
|
|
||||||
)
|
|
||||||
|
|
||||||
for name in "${list_sources_pairs[@]}"; do
|
|
||||||
local list_file="/etc/apt/sources.list.d/${name}.list"
|
|
||||||
local sources_file="/etc/apt/sources.list.d/${name}.sources"
|
|
||||||
|
|
||||||
if [[ -f "$list_file" && -f "$sources_file" ]]; then
|
|
||||||
if grep -q "^Enabled: *true" "$sources_file"; then
|
|
||||||
msg_info "$(translate "Removing redundant file: $(basename "$list_file")")"
|
|
||||||
rm -f "$list_file"
|
|
||||||
cleaned_count=$((cleaned_count + 1))
|
cleaned_count=$((cleaned_count + 1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -f "/etc/apt/sources.list.d/debian.sources" ]; then
|
if [ -f "/etc/apt/sources.list.d/debian.sources" ]; then
|
||||||
for uri in $(grep -E '^UR[IL]:' /etc/apt/sources.list.d/debian.sources | awk '{print $2}'); do
|
|
||||||
if [[ "$uri" == *security.debian.org* ]]; then
|
if grep -q "^deb.*deb\.debian\.org" "$sources_file"; then
|
||||||
if grep -q "^deb.*${uri//\//\\/}" "$sources_file"; then
|
sed -i '/^deb.*deb\.debian\.org/s/^/# /' "$sources_file"
|
||||||
sed -i "/^deb.*${uri//\//\\/}/s/^/# /" "$sources_file"
|
|
||||||
cleaned_count=$((cleaned_count + 1))
|
cleaned_count=$((cleaned_count + 1))
|
||||||
msg_info "$(translate "Commented security.debian.org lines in sources.list (using .sources format)")"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for list_file in /etc/apt/sources.list.d/*.list; do
|
if grep -q "^deb.*security\.debian\.org" "$sources_file"; then
|
||||||
[[ -f "$list_file" ]] || continue
|
sed -i '/^deb.*security\.debian\.org/s/^/# /' "$sources_file"
|
||||||
if grep -q "^deb.*${uri//\//\\/}" "$list_file"; then
|
|
||||||
sed -i "/^deb.*${uri//\//\\/}/s/^/# /" "$list_file"
|
|
||||||
cleaned_count=$((cleaned_count + 1))
|
cleaned_count=$((cleaned_count + 1))
|
||||||
msg_info "$(translate "Commented security.debian.org lines in $(basename "$list_file") (using .sources format)")"
|
|
||||||
fi
|
fi
|
||||||
done
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
rm -f "$old_file"
|
||||||
|
cleaned_count=$((cleaned_count + 1))
|
||||||
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$cleaned_count" -gt 0 ]; then
|
if [ $cleaned_count -gt 0 ]; then
|
||||||
msg_ok "$(translate "Cleaned up $cleaned_count duplicate/old repositories")"
|
msg_ok "$(translate "Cleaned up $cleaned_count duplicate/old repositories")"
|
||||||
apt-get update > /dev/null 2>&1 || true
|
apt-get update > /dev/null 2>&1 || true
|
||||||
else
|
else
|
||||||
msg_ok "$(translate "No duplicate repositories found")"
|
msg_ok "$(translate "No duplicate repositories found")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cleanup_duplicate_repos_pve9_() {
|
||||||
cleanup_duplicate_repos_pve9() {
|
|
||||||
msg_info "$(translate "Cleaning up duplicate repositories...")"
|
msg_info "$(translate "Cleaning up duplicate repositories...")"
|
||||||
|
|
||||||
local sources_file="/etc/apt/sources.list"
|
local sources_file="/etc/apt/sources.list"
|
||||||
local temp_file
|
local temp_file=$(mktemp)
|
||||||
local cleaned_count=0
|
local cleaned_count=0
|
||||||
declare -A seen_repos
|
declare -A seen_repos
|
||||||
|
|
||||||
|
|
||||||
temp_file=$(mktemp)
|
|
||||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
|
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
|
||||||
echo "$line" >> "$temp_file"
|
echo "$line" >> "$temp_file"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$line" =~ ^deb ]]; then
|
if [[ "$line" =~ ^deb ]]; then
|
||||||
read -r _ url dist components <<< "$line"
|
read -r _ url dist components <<< "$line"
|
||||||
local key="${url}_${dist}"
|
local key="${url}_${dist}"
|
||||||
@ -219,33 +202,43 @@ cleanup_duplicate_repos_pve9() {
|
|||||||
echo "$line" >> "$temp_file"
|
echo "$line" >> "$temp_file"
|
||||||
fi
|
fi
|
||||||
done < "$sources_file"
|
done < "$sources_file"
|
||||||
|
|
||||||
mv "$temp_file" "$sources_file"
|
mv "$temp_file" "$sources_file"
|
||||||
chmod 644 "$sources_file"
|
chmod 644 "$sources_file"
|
||||||
|
|
||||||
|
for src in proxmox debian ceph; do
|
||||||
|
local sources_path="/etc/apt/sources.list.d/${src}.sources"
|
||||||
|
if [ -f "$sources_path" ]; then
|
||||||
|
case "$src" in
|
||||||
|
proxmox)
|
||||||
|
url_match="download.proxmox.com"
|
||||||
|
;;
|
||||||
|
debian)
|
||||||
|
url_match="deb.debian.org"
|
||||||
|
;;
|
||||||
|
ceph)
|
||||||
|
url_match="download.proxmox.com/ceph"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
url_match=""
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
for sources_path in /etc/apt/sources.list.d/*.sources; do
|
if [[ -n "$url_match" ]]; then
|
||||||
[[ -f "$sources_path" ]] || continue
|
if grep -q "^deb.*$url_match" "$sources_file"; then
|
||||||
|
sed -i "/^deb.*$url_match/s/^/# /" "$sources_file"
|
||||||
if ! grep -qi '^Enabled: *true' "$sources_path"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
while read -r uri; do
|
|
||||||
|
|
||||||
if grep -q "^deb.*${uri//\//\\/}" "$sources_file"; then
|
|
||||||
sed -i "/^deb.*${uri//\//\\/}/s/^/# /" "$sources_file"
|
|
||||||
cleaned_count=$((cleaned_count + 1))
|
cleaned_count=$((cleaned_count + 1))
|
||||||
msg_info "$(translate "Commented duplicated repo ($uri) in sources.list")"
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
for list_file in /etc/apt/sources.list.d/*.list; do
|
for list_file in /etc/apt/sources.list.d/*.list; do
|
||||||
[[ -f "$list_file" ]] || continue
|
[[ -f "$list_file" ]] || continue
|
||||||
if grep -q "^deb.*${uri//\//\\/}" "$list_file"; then
|
if grep -q "^deb.*$url_match" "$list_file"; then
|
||||||
sed -i "/^deb.*${uri//\//\\/}/s/^/# /" "$list_file"
|
sed -i "/^deb.*$url_match/s/^/# /" "$list_file"
|
||||||
cleaned_count=$((cleaned_count + 1))
|
cleaned_count=$((cleaned_count + 1))
|
||||||
msg_info "$(translate "Commented duplicated repo ($uri) in $(basename "$list_file")")"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done < <(grep -E '^UR[IL]:' "$sources_path" | awk '{print $2}')
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $cleaned_count -gt 0 ]; then
|
if [ $cleaned_count -gt 0 ]; then
|
||||||
@ -260,7 +253,6 @@ cleanup_duplicate_repos_pve9() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cleanup_duplicate_repos_pve8() {
|
cleanup_duplicate_repos_pve8() {
|
||||||
msg_info "$(translate "Cleaning up duplicate repositories...")"
|
msg_info "$(translate "Cleaning up duplicate repositories...")"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user