]> xenbits.xensource.com Git - xenclient/build.git/commitdiff
[host installer] better at finding optical media
authorChristopher Clark <christopher.clark@citrix.com>
Thu, 10 Sep 2009 04:30:28 +0000 (21:30 -0700)
committerChristopher Clark <christopher.clark@citrix.com>
Thu, 10 Sep 2009 04:30:28 +0000 (21:30 -0700)
target/generic/target_xenclient_installer_skeleton/install/stages/Locate-optical-failed [new file with mode: 0755]
target/generic/target_xenclient_installer_skeleton/install/stages/Locate-optical-media
target/generic/target_xenclient_installer_skeleton/install/stages/sequence.graph

diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/Locate-optical-failed b/target/generic/target_xenclient_installer_skeleton/install/stages/Locate-optical-failed
new file mode 100755 (executable)
index 0000000..396d2d2
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/ash
+
+. ${SCRIPT_DIR}/functions
+
+if interactive ; then
+    echo "Interactive: offering user another chance to supply optical media.">&2
+    exit ${Retry}
+fi
+exit ${Abort}
index 06d65a5bd868d36d9404339ab6191fcdd088bdd8..116f583f9847e435f90fb5b6c9cdebb8fb15d51b 100755 (executable)
@@ -3,7 +3,98 @@
 . ${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"
 
@@ -22,7 +113,8 @@ if answerfile_specifies "source" ; then
     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
@@ -38,11 +130,10 @@ if answerfile_specifies "source" ; then
     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}"
 
index 6ec8db21e27f4a9b4e2355bfb30263638b4b9618..85d38130352d4d0aece6ccfc87441d198c6ddb93 100644 (file)
@@ -12,7 +12,9 @@ Check-GPU,               Continue:Choose-install-type | Abort:Fail
 
 Choose-install-type,     Optical:Locate-optical-media | Network:Select-NIC | BootMedia:Check-initrd-data | Abort:Fail
 
-Locate-optical-media,    Continue:Mount-optical-media | Abort:Fail
+Locate-optical-media,    Continue:Mount-optical-media | LocateFail:Locate-optical-failed | Abort:Fail
+Locate-optical-failed,   Retry:Choose-install-type | Abort:Fail
+
 Mount-optical-media,     Continue:Verify-optical-media | MountFail:Bad-install-choice | Abort:Fail
 Verify-optical-media,    Continue:Find-existing-install | VerifyFail:Bad-install-choice | Abort:Fail