fix: correctly detect and remove CD-ROM apt sources on Ubuntu 26
The previous check only matched "cdrom:" but Ubuntu 26 uses DEB822 format with "URIs: file:///cdrom". Now matches /cdrom broadly and handles .sources files, .list files, and traditional sources.list. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+37
-17
@@ -188,27 +188,47 @@ install_git() {
|
||||
# apt-get update once the machine has internet sources configured.
|
||||
# Remove it automatically so the rest of the script can proceed.
|
||||
clean_cdrom_sources() {
|
||||
# Traditional sources.list format
|
||||
if grep -qE '^\s*deb\s.*cdrom:' /etc/apt/sources.list 2>/dev/null; then
|
||||
has_internet=false
|
||||
if grep -E '^\s*deb\s' /etc/apt/sources.list 2>/dev/null | grep -qv 'cdrom:'; then
|
||||
# Check if any internet (non-cdrom) apt sources exist
|
||||
has_internet=false
|
||||
# Traditional sources.list
|
||||
if [ -f /etc/apt/sources.list ] && \
|
||||
grep -qE '^\s*deb\s' /etc/apt/sources.list 2>/dev/null; then
|
||||
if ! grep -E '^\s*deb\s' /etc/apt/sources.list | grep -q '/cdrom'; then
|
||||
has_internet=true
|
||||
elif grep -rE '^\s*deb\s' /etc/apt/sources.list.d/ 2>/dev/null | grep -qv 'cdrom:'; then
|
||||
has_internet=true
|
||||
fi
|
||||
if [ "$has_internet" = true ]; then
|
||||
info "Removing CD-ROM apt source (internet sources detected)"
|
||||
psudo sed -i '/cdrom:/d' /etc/apt/sources.list
|
||||
fi
|
||||
fi
|
||||
# DEB822 format (.sources files)
|
||||
for f in /etc/apt/sources.list.d/*.sources; do
|
||||
[ -f "$f" ] || continue
|
||||
if grep -qE '^\s*URIs:\s*.*cdrom:' "$f" 2>/dev/null; then
|
||||
info "Removing CD-ROM apt source from $(basename "$f")"
|
||||
psudo sed -i '/URIs:.*cdrom:/d' "$f"
|
||||
# .list files in sources.list.d
|
||||
if [ "$has_internet" = false ] && \
|
||||
grep -rE '^\s*deb\s' /etc/apt/sources.list.d/*.list 2>/dev/null | grep -qv '/cdrom'; then
|
||||
has_internet=true
|
||||
fi
|
||||
# DEB822 .sources files with http/https URIs
|
||||
if [ "$has_internet" = false ]; then
|
||||
for f in /etc/apt/sources.list.d/*.sources; do
|
||||
[ -f "$f" ] || continue
|
||||
if grep -qE '^\s*URIs:\s*https?://' "$f" 2>/dev/null; then
|
||||
has_internet=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "$has_internet" = true ]; then
|
||||
# Remove cdrom entries from traditional sources.list
|
||||
if [ -f /etc/apt/sources.list ] && \
|
||||
grep -q '/cdrom' /etc/apt/sources.list 2>/dev/null; then
|
||||
info "Removing CD-ROM apt source from sources.list"
|
||||
psudo sed -i '/\/cdrom/d' /etc/apt/sources.list
|
||||
fi
|
||||
done
|
||||
# Remove cdrom .sources files entirely
|
||||
for f in /etc/apt/sources.list.d/*.sources; do
|
||||
[ -f "$f" ] || continue
|
||||
if grep -q '/cdrom' "$f" 2>/dev/null; then
|
||||
info "Removing $(basename "$f") (CD-ROM source)"
|
||||
psudo rm -f "$f"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
info "Installing git via system package manager ..."
|
||||
|
||||
Reference in New Issue
Block a user