]> xenbits.xensource.com Git - xenclient/build.git/commitdiff
[host installer] tidy up detection of interactive
authorChristopher Clark <cclark@xc-build.home>
Wed, 26 Aug 2009 21:32:06 +0000 (14:32 -0700)
committerChristopher Clark <cclark@xc-build.home>
Wed, 26 Aug 2009 21:32:06 +0000 (14:32 -0700)
target/generic/target_xenclient_installer_skeleton/install/stages/Check-initrd-data
target/generic/target_xenclient_installer_skeleton/install/stages/Configure-DHCP
target/generic/target_xenclient_installer_skeleton/install/stages/Download-install-files
target/generic/target_xenclient_installer_skeleton/install/stages/Mount-optical-media
target/generic/target_xenclient_installer_skeleton/install/stages/Trash-and-install
target/generic/target_xenclient_installer_skeleton/install/stages/Verify-optical-media
target/generic/target_xenclient_installer_skeleton/install/stages/functions

index b63b70991a63ce498bc67806de9e832a3156d4fb..77c5fd299e8fb0f681943c036cae1c16558ddecf 100755 (executable)
@@ -14,21 +14,18 @@ link_bootmedia_repo()
     [ -r "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}/${DOM0_ROOTFS}" ] || exit ${CheckFail}
 }
 
-INTERACTIVE=0
-interactive || INTERACTIVE=1
-
-[ ${INTERACTIVE} -ne 0 ] || mixedgauge "Verifying repository." 5
+mixedgauge "Verifying repository." 5
 
 # Verify the repo:
 if ! validate_repo "/${PACKAGES_DOT_MAIN}" "${INTERACTIVE}" ; then
-    [ ${INTERACTIVE} -ne 0 ] || dialog --ok-label Continue --msgbox "ERROR: Install media verification failed." 0 0
+    ! interactive || dialog --ok-label Continue --msgbox "ERROR: Install media verification failed." 0 0
     exit ${CheckFail}
 fi
 
 # Make the repo available for the installer:
 link_bootmedia_repo
 
-if [ ${INTERACTIVE} -ne 0 ] ; then
+if ! interactive ; then
     not_previous $@ || exit ${Previous}
 fi
 exit ${Continue}
index c797aed965be88ea40af68f82048c666fabc213f..a9804042dc39c8a209672b4ff099f98437d83066 100755 (executable)
@@ -25,14 +25,11 @@ iface ${NIC} inet dhcp"
     return 0
 }
 
-INTERACTIVE=0
-interactive || INTERACTIVE=1
-
-[ ${INTERACTIVE} -ne 0 ] || mixedgauge "Obtaining IP address..." 30
+mixedgauge "Obtaining IP address..." 30
 
 if ! apply_config_to_nic ; then
     echo "Failure when bringing up ${NIC}.">&2
-    if [ ${INTERACTIVE} -eq 0 ] ; then
+    if interactive ; then
         hide_cursor
         do_cmd dialog --ok-label Continue --msgbox "\nError: failed to obtain IP address." 7 40
         exit ${NoAddress}
index 10ae233fbd50405235f6d1fd0e8456b2ebcfaaaa..56a11f8c026f8acd8592dc861777abf99657fd79 100755 (executable)
@@ -20,10 +20,6 @@ fi
 
 # FIXME: distinguish Abort from BadConfig exit conditions.
 
-#-----------------------------------------------------------
-INTERACTIVE=0
-interactive || INTERACTIVE=1
-
 #-----------------------------------------------------------
 wget_file()
 {
@@ -57,7 +53,7 @@ do_wget_transfer()
     BASE_URL="$1"
 
     PERCENT="2"
-    [ ${INTERACTIVE} -ne 0 ] || mixedgauge "Downloading manifest..." "${PERCENT}"
+    mixedgauge "Downloading manifest..." "${PERCENT}"
 
     wget_file "${BASE_URL}" "${PACKAGES_DOT_MAIN}/${REPOSITORY_FILENAME}" || return 1
     wget_file "${BASE_URL}" "${PACKAGES_DOT_MAIN}/${PKGDATA_FILENAME}"    || return 1
@@ -69,7 +65,7 @@ do_wget_transfer()
     PKG_LIST="$(package_list ${PKGDATA_FILE})"
     PERCENT="10" # FIXME: proper calculation
     for FILENAME in ${PKG_LIST} ; do
-        [ ${INTERACTIVE} -ne 0 ] || mixedgauge "Downloading ${FILENAME}..." "${PERCENT}"
+        mixedgauge "Downloading ${FILENAME}..." "${PERCENT}"
         wget_file "${BASE_URL}" "${PACKAGES_DOT_MAIN}/${FILENAME}" || return 1
         PERCENT="$(( PERCENT + 50 ))" # FIXME: proper calculation
     done
@@ -168,7 +164,7 @@ nfs)
     ;;
 esac
 
-[ ${INTERACTIVE} -ne 0 ] || mixedgauge "Download complete." "100"
+mixedgauge "Download complete." "100"
 
 # FIXME: when checking to see if download was successful:
 #        if not: if interactive, return ${Previous}, else return ${Abort}
index a03e71961a18d9253e1b76a1cb1f1118e38d64c2..c031035d66c566057233732d73a9df99e15c8d37 100755 (executable)
@@ -18,14 +18,11 @@ fi
 # A precautionary umount, failure here is fine
 umount "${OPTICAL_MOUNT}" 2>/dev/null
 
-INTERACTIVE=0
-interactive || INTERACTIVE=1
-
-[ ${INTERACTIVE} -ne 0 ] || mixedgauge "Mounting optical device." 30
+mixedgauge "Mounting optical device." 30
 
 mkdir -p "${OPTICAL_MOUNT}"
 mount "${OPTICAL_DEV}" "${OPTICAL_MOUNT}" || exit ${MountFail}
 
-[ ${INTERACTIVE} -ne 0 ] || mixedgauge "Mounted optical device." 100
+mixedgauge "Mounted optical device." 100
 
 exit ${Continue}
index 8fe3c5e2864b237781de99adfd1efea44848d7ea..25fa0f4cbf30f4f125d1f044dfc21d2fc9ad4878 100755 (executable)
@@ -7,11 +7,6 @@
 
 DEV="/dev/${TARGET_DISK}"
 
-# FIXME: 
-if ! interactive ; then
-    d(){ :;} # redefine d to nothing so no dialogs are shown
-fi
-
 mixedgauge "Removing previous partitions." 0
 do_cmd vgchange -a n >&2 || die
 for i in ${DEV}[1-4]
index 83dfc277eaee027a02916632dc0647ee77f02440..9895f7dae8fc0a3b5511807a120db6b9bb64a275 100755 (executable)
@@ -24,11 +24,8 @@ if [ "${OPTICAL_VERIFY}" = "no" ] ; then
     exit ${Continue}
 fi
 
-INTERACTIVE=0
-interactive || INTERACTIVE=1
-
 # If interactive, ask:
-if [ "${OPTICAL_VERIFY}" = "ask_or_yes" ] && [ ${INTERACTIVE} -eq 0 ] ; then
+if [ "${OPTICAL_VERIFY}" = "ask_or_yes" ] && interactive ; then
     dialog --yes-label Verify --no-label Skip --yesno "\n     Verify the CD-ROM media?" 7 40
 
     OPT=$?
@@ -40,18 +37,18 @@ if [ "${OPTICAL_VERIFY}" = "ask_or_yes" ] && [ ${INTERACTIVE} -eq 0 ] ; then
     [ "$OPT" != "255" ] || exit ${Previous}
 fi
 
-[ ${INTERACTIVE} -ne 0 ] || mixedgauge "Verifying repository." 5
+mixedgauge "Verifying repository." 5
 
 # Verify the repo:
 if ! validate_repo "${OPTICAL_MOUNT}/${PACKAGES_DOT_MAIN}" "${INTERACTIVE}" ; then
-    [ ${INTERACTIVE} -ne 0 ] || dialog --ok-label Continue --msgbox "ERROR: CD-ROM verification failed." 0 0
+    ! interactive || dialog --ok-label Continue --msgbox "ERROR: CD-ROM verification failed." 0 0
     exit ${VerifyFail}
 fi
 
 # Make the repo available for the installer:
 link_optical_repo
 
-if [ "${OPTICAL_VERIFY}" != "ask_or_yes" ] || [ ${INTERACTIVE} -ne 0 ] ; then
+if [ "${OPTICAL_VERIFY}" != "ask_or_yes" ] || ! interactive ; then
     not_previous $@ || exit ${Previous}
 fi
 exit ${Continue}
index f2b83398ddae2fc324ed2d860756e47bba08e740..32f8dd7ae318b0d1732d55e168f595a35faabb4a 100644 (file)
@@ -110,10 +110,16 @@ mixedgauge()
     text="$1"
     percent="$2"
     hide_cursor
-    d --mixedgauge "$text" 0 0 "$percent"
+    if [ ${INTERACTIVE} -ne 0 ] ; then
+        echo "${text}">&2
+    else
+        d --mixedgauge "$text" 0 0 "$percent"
+    fi
 }
 
-interactive()
+# Make the 'interactive' function cheaper by only reading
+# the contents of the config file once, here, and caching.
+read_interactive()
 {
     # 0: is interactive
     # 1: non-interactive
@@ -121,6 +127,12 @@ interactive()
     grep -qi "AUTOMATED=True" <"${AUTOMATED_CONF}" || return 0
     return 1
 }
+export INTERACTIVE=0
+read_interactive || export INTERACTIVE=1
+interactive()
+{
+    return ${INTERACTIVE}
+}
 
 KCMD_LINE="/install/data/kcmdline" # copy of /proc/cmdline
 
@@ -307,7 +319,7 @@ validate_repo()
         MANIFEST_SIZE="$(sed -ne 's/^\S\+\s\+\(\S\+\)\s\+\(\S\+\s\+\)\{3\}\('${FILENAME}'\)\s.*$/\1/p' <${PKGDATA_FILE})"
         FILE="${REPO_DIR}/${FILENAME}"
 
-        [ ${INTERACTIVE} -ne 0 ] || mixedgauge "Verifying: ${FILENAME}" "${PERCENT}"
+        mixedgauge "Verifying: ${FILENAME}" "${PERCENT}"
         FILE_MD5SUM="$(md5sum ${FILE} | cut -f1 -d' ')"
         PERCENT="$(( PERCENT + 50 ))" # FIXME: proper calculation