fix: auto-remove CD-ROM apt source when internet sources are available
On minimal Ubuntu installs, the CD-ROM source persists in sources.list and breaks apt-get update. Now detect and remove it before installing git, and verify git is actually available after installation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -184,13 +184,45 @@ install_git() {
|
||||
success "git already installed ($(git --version))"
|
||||
return
|
||||
fi
|
||||
# On some Ubuntu installs the CD-ROM source is still present and breaks
|
||||
# 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
|
||||
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"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
info "Installing git via system package manager ..."
|
||||
case "$DISTRO" in
|
||||
aosc) psudo oma install -y git ;;
|
||||
debian|ubuntu) psudo apt-get update -qq && psudo apt-get install -y git ;;
|
||||
debian|ubuntu) clean_cdrom_sources; psudo apt-get update -qq; psudo apt-get install -y git ;;
|
||||
fedora) psudo dnf install -y git ;;
|
||||
esac
|
||||
success "git installed"
|
||||
if command -v git &>/dev/null; then
|
||||
success "git installed ($(git --version))"
|
||||
else
|
||||
error "git installation failed"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ─── Homebrew ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user