From 2cd0ba9ebf7f445033c8c32573656d10a4939007 Mon Sep 17 00:00:00 2001 From: Christopher Clark Date: Wed, 26 Aug 2009 14:32:06 -0700 Subject: [PATCH] [host installer] tidy up detection of interactive --- .../install/stages/Check-initrd-data | 9 +++------ .../install/stages/Configure-DHCP | 7 ++----- .../install/stages/Download-install-files | 10 +++------- .../install/stages/Mount-optical-media | 7 ++----- .../install/stages/Trash-and-install | 5 ----- .../install/stages/Verify-optical-media | 11 ++++------- .../install/stages/functions | 18 +++++++++++++++--- 7 files changed, 29 insertions(+), 38 deletions(-) diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/Check-initrd-data b/target/generic/target_xenclient_installer_skeleton/install/stages/Check-initrd-data index b63b709..77c5fd2 100755 --- a/target/generic/target_xenclient_installer_skeleton/install/stages/Check-initrd-data +++ b/target/generic/target_xenclient_installer_skeleton/install/stages/Check-initrd-data @@ -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} diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/Configure-DHCP b/target/generic/target_xenclient_installer_skeleton/install/stages/Configure-DHCP index c797aed..a980404 100755 --- a/target/generic/target_xenclient_installer_skeleton/install/stages/Configure-DHCP +++ b/target/generic/target_xenclient_installer_skeleton/install/stages/Configure-DHCP @@ -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} diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/Download-install-files b/target/generic/target_xenclient_installer_skeleton/install/stages/Download-install-files index 10ae233..56a11f8 100755 --- a/target/generic/target_xenclient_installer_skeleton/install/stages/Download-install-files +++ b/target/generic/target_xenclient_installer_skeleton/install/stages/Download-install-files @@ -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} diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/Mount-optical-media b/target/generic/target_xenclient_installer_skeleton/install/stages/Mount-optical-media index a03e719..c031035 100755 --- a/target/generic/target_xenclient_installer_skeleton/install/stages/Mount-optical-media +++ b/target/generic/target_xenclient_installer_skeleton/install/stages/Mount-optical-media @@ -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} diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/Trash-and-install b/target/generic/target_xenclient_installer_skeleton/install/stages/Trash-and-install index 8fe3c5e..25fa0f4 100755 --- a/target/generic/target_xenclient_installer_skeleton/install/stages/Trash-and-install +++ b/target/generic/target_xenclient_installer_skeleton/install/stages/Trash-and-install @@ -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] diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/Verify-optical-media b/target/generic/target_xenclient_installer_skeleton/install/stages/Verify-optical-media index 83dfc27..9895f7d 100755 --- a/target/generic/target_xenclient_installer_skeleton/install/stages/Verify-optical-media +++ b/target/generic/target_xenclient_installer_skeleton/install/stages/Verify-optical-media @@ -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} diff --git a/target/generic/target_xenclient_installer_skeleton/install/stages/functions b/target/generic/target_xenclient_installer_skeleton/install/stages/functions index f2b8339..32f8dd7 100644 --- a/target/generic/target_xenclient_installer_skeleton/install/stages/functions +++ b/target/generic/target_xenclient_installer_skeleton/install/stages/functions @@ -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 -- 2.39.5