#! /bin/sh
set -e

. /usr/share/debconf/confmodule

# Can be preseed to true to force cdrom entries to be disabled
db_get apt-setup/disable-cdrom-entries
disable_cdrom_entries="$RET"

# Always disable CD image in sources.list if any other sources are present
if ([ -e /cdrom/.disk/base_installable ] || [ "$OVERRIDE_BASE_INSTALLABLE" ]) && \
   grep -q "^deb \(ht\|f\)tp" /target/etc/apt/sources.list; then
	disable_cdrom_entries="true"
fi

# Comment out the cdrom entries and update APT's cache
if [ "$disable_cdrom_entries" = "true" ]; then
	logger -t finish-install "Disabling CDROM entries in sources.list"
	sed -i "/^deb cdrom:/s/^/#/" /target/etc/apt/sources.list
fi
