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:
FlintyLemming
2026-04-07 20:41:53 +08:00
parent 3ba41ddbcb
commit e4e1afebe8
+32 -12
View File
@@ -188,27 +188,47 @@ install_git() {
# apt-get update once the machine has internet sources configured. # apt-get update once the machine has internet sources configured.
# Remove it automatically so the rest of the script can proceed. # Remove it automatically so the rest of the script can proceed.
clean_cdrom_sources() { clean_cdrom_sources() {
# Traditional sources.list format # Check if any internet (non-cdrom) apt sources exist
if grep -qE '^\s*deb\s.*cdrom:' /etc/apt/sources.list 2>/dev/null; then
has_internet=false has_internet=false
if grep -E '^\s*deb\s' /etc/apt/sources.list 2>/dev/null | grep -qv 'cdrom:'; then # Traditional sources.list
has_internet=true if [ -f /etc/apt/sources.list ] && \
elif grep -rE '^\s*deb\s' /etc/apt/sources.list.d/ 2>/dev/null | grep -qv 'cdrom:'; then 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 has_internet=true
fi 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
# .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 fi
# DEB822 format (.sources files) # DEB822 .sources files with http/https URIs
if [ "$has_internet" = false ]; then
for f in /etc/apt/sources.list.d/*.sources; do for f in /etc/apt/sources.list.d/*.sources; do
[ -f "$f" ] || continue [ -f "$f" ] || continue
if grep -qE '^\s*URIs:\s*.*cdrom:' "$f" 2>/dev/null; then if grep -qE '^\s*URIs:\s*https?://' "$f" 2>/dev/null; then
info "Removing CD-ROM apt source from $(basename "$f")" has_internet=true
psudo sed -i '/URIs:.*cdrom:/d' "$f" break
fi fi
done 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
# 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 ..." info "Installing git via system package manager ..."