. ${SCRIPT_DIR}/functions
# This script selects and records the optical device in use.
-OPTICAL_DEVICE="${DEFAULT_OPTICAL_DEVICE}"
+
+#------------------------------------------------------------
+list_cdrom_devices()
+{
+ sed -ne 's/^drive name:\s*//p' </proc/sys/dev/cdrom/info 2>/dev/null
+}
+
+#------------------------------------------------------------
+dev_provides_repo()
+{
+ CD_DEV="/dev/$1"
+ MNT=$(mktemp -d)
+ FOUND=1
+ do_cmd mount "${CD_DEV}" "${MNT}" || return 1
+ # A coarse check: existence of the packages directory:
+ [ ! -e "${MNT}/${PACKAGES_DOT_MAIN}" ] || FOUND=0
+ do_cmd umount "${MNT}" || return 1
+ rmdir ${MNT}
+ [ ${FOUND} -ne 1 ] || return 1
+ return 0
+}
+
+#------------------------------------------------------------
+locate_cdrom()
+{
+ DEVICES=$(list_cdrom_devices)
+ DEV_COUNT=0
+ for DEV in ${DEVICES} ; do
+ DEV_COUNT=$((DEV_COUNT + 1))
+ done
+
+ case "${DEV_COUNT}" in
+ 0)
+ echo "ERROR: Cannot identify -any- CD-Rom devices.">&2
+ if interactive ; then
+ dialog --colors --ok-label "Continue" --msgbox \
+" \ZbERROR: Cannot locate any optical media device\ZB
+
+ Please select an alternative method of installation." 8 60
+ fi
+ exit ${LocateFail}
+ ;;
+ 1)
+ OPTICAL_DEVICE="${DEVICES}"
+ echo "Selecting sole CD-Rom device: ${OPTICAL_DEVICE}">&2
+ ;;
+ *)
+ # Multiple CD-Rom devices
+ # Ideally we'd identify the one we booted off, but instead
+ # we'll just search for repositories. If we find multiple,
+ # we could do version checking of repo vs. installer, but
+ # instead we're going to insist on user intervention.
+ REPO_DEVICES=""
+ REPO_COUNT=0
+ for DEV in ${DEVICES} ; do
+ if dev_provides_repo "${DEV}" ; then
+ REPO_DEVICES="${REPO_DEVICES}${REPO_DEVICES:+ }${DEV}"
+ REPO_COUNT=$((REPO_COUNT + 1))
+ fi
+ done
+ case "${REPO_COUNT}" in
+ 0)
+ echo "ERROR: Multiple CD-Rom devices but cannot locate a repository.">&2
+ if interactive ; then
+ dialog --colors --ok-label "Continue" --msgbox \
+ " \ZbERROR: Cannot find optical media device repository\ZB
+
+ Please check your media or installation method." 8 65
+ fi
+ exit ${LocateFail}
+ ;;
+ 1)
+ OPTICAL_DEVICE="${REPO_DEVICES}"
+ echo "Selecting CD-Rom device: ${OPTICAL_DEVICE}">&2
+ ;;
+ *)
+ echo "ERROR: Multiple CD-Rom devices and MULTIPLE repositories found.">&2
+ if interactive ; then
+ dialog --colors --ok-label "Continue" --msgbox \
+ ' \ZbERROR: Cannot determine which repository to use!\ZB
+
+ Please eject your unnecessary media.' 8 60
+ fi
+ exit ${LocateFail}
+ ;;
+
+ esac
+ ;;
+ esac
+}
+
+#------------------------------------------------------------
DO_VERIFY="ask_or_yes"
SOURCE_DEVICE=$(read_xml_tag "${ANSWERFILE}" "source")
if [ -z "${SOURCE_DEVICE}" ] ; then
# warning, not fatal:
- echo "Answerfile <source type=local> did not specify device - assuming default.">&2
+ echo "Answerfile <source type=local> did not specify device so will scan.">&2
+ locate_cdrom
else
OPTICAL_DEVICE="${SOURCE_DEVICE}"
fi
elif [ "x${VERFIY}" = "xyes" ] || [ "x${VERIFY}" = "xtrue" ] ; then
DO_VERIFY="yes"
fi
+else
+ locate_cdrom
fi
-#FIXME: if interactive and multiple optical devices present,
-# allow the user to select from available devices.
-
echo "OPTICAL_DEVICE=${OPTICAL_DEVICE}">"${OPTICAL_CONF}"
echo "OPTICAL_VERIFY=${DO_VERIFY}">>"${OPTICAL_CONF}"