Darryl L. Pierce
2009-Jun-30 18:32 UTC
[Ovirt-devel] [PATCH node] Make all yes/no prompts consistent. rhbz#508778
Added a new function, "ask_yes_or_no", to ovirt-functions. It contains a default prompt if none is provided. Changed all prompts that ask for yes, no and/or abort to use this new method. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- scripts/ovirt-config-boot-wrapper | 8 ++--- scripts/ovirt-config-collectd | 39 +++++++++++++++----------- scripts/ovirt-config-logging | 45 ++++++++++++++++-------------- scripts/ovirt-config-networking | 55 +++++++++++++++++++----------------- scripts/ovirt-config-storage | 30 ++++++++------------ scripts/ovirt-config-uninstall | 4 +-- scripts/ovirt-functions | 18 ++++++++++++ 7 files changed, 109 insertions(+), 90 deletions(-) diff --git a/scripts/ovirt-config-boot-wrapper b/scripts/ovirt-config-boot-wrapper index ff6f6e5..4ce9969 100755 --- a/scripts/ovirt-config-boot-wrapper +++ b/scripts/ovirt-config-boot-wrapper @@ -24,14 +24,12 @@ continuing." else bootparams="${OVIRT_BOOTPARAMS}" fi - read -p "Do you wish to continue (Y/n)? " - r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]') - if [ "$r" == "Y" ]; then + if ask_yes_or_no; then mount_live \ - && /usr/sbin/ovirt-config-boot /live "${bootparams}" + && /usr/sbin/ovirt-config-boot /live "${bootparams}" rc=$? break - elif [ "$r" == "N" ]; then + else printf "\nExiting back to the menu\n" rc=99 break diff --git a/scripts/ovirt-config-collectd b/scripts/ovirt-config-collectd index 236ddaa..11811fd 100755 --- a/scripts/ovirt-config-collectd +++ b/scripts/ovirt-config-collectd @@ -67,23 +67,28 @@ prompt_user() { printf "\n" printf "\n" while true; do - read -p "Is this correct (Y/N/A)? " - r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]') - if [ "$r" == "Y" ]; then - printf "\nSaving configuration.\n" - if [[ -n "$collectd_server_ip" ]] && - [[ -n "$collectd_server_port" ]]; then - ovirt_collectd $collectd_server_ip \ - $collectd_server_port - fi - return - elif [ "$r" == "N" ]; then - printf "\nRestarting collectd configuration.\n" - break - elif [ "$r" == "A" ]; then - printf "\nAborting collectd configuration.\n" - return - fi + ask_yes_or_no "Is this correct (y/n/a)?" + rc=$? + case $rc in + 0) + printf "\nSaving configuration.\n" + if [[ -n "$collectd_server_ip" ]] && + [[ -n "$collectd_server_port" ]]; then + ovirt_collectd $collectd_server_ip \ + $collectd_server_port + fi + return + ;; + + 1) + printf "\nRestarting collectd configuration.\n" + break + ;; + 2) + printf "\nAborting collectd configuration.\n" + return + ;; + esac done done } diff --git a/scripts/ovirt-config-logging b/scripts/ovirt-config-logging index ba661c3..bb0f082 100755 --- a/scripts/ovirt-config-logging +++ b/scripts/ovirt-config-logging @@ -146,27 +146,30 @@ function prompt_user { printf "\n" printf "\n" while true; do - read -p "Is this correct (Y/N/A)? " - r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]') - if [ "$r" == "Y" ]; then - printf "\nSaving configuration.\n" - if [[ -n "$syslog_server_ip" ]] && - [[ -n "$syslog_server_port" ]] && - [[ -n "$syslog_server_protocol" ]]; then - ovirt_rsyslog $syslog_server_ip \ - $syslog_server_port \ - $syslog_server_protocol - fi - sed -c -i -e "s/^size=.*/size=${max_log_size}k/" \ - /etc/logrotate.d/ovirt-logrotate.conf - return - elif [ "$r" == "N" ]; then - printf "\nRestarting logging configuration.\n" - break - elif [ "$r" == "A" ]; then - printf "\nAborting logging configuration.\n" - return - fi + ask_yes_or_no "Is this correct (y/n/a)?" + case $? in + 0) + printf "\nSaving configuration.\n" + if [[ -n "$syslog_server_ip" ]] && + [[ -n "$syslog_server_port" ]] && + [[ -n "$syslog_server_protocol" ]]; then + ovirt_rsyslog $syslog_server_ip \ + $syslog_server_port \ + $syslog_server_protocol + fi + sed -c -i -e "s/^size=.*/size=${max_log_size}k/" \ + /etc/logrotate.d/ovirt-logrotate.conf + return + ;; + 1) + printf "\nRestarting logging configuration.\n" + break + ;; + 2) + printf "\nAborting logging configuration.\n" + return + ;; + esac done done } diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index d29bd12..713cabc 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -40,10 +40,12 @@ function configure_interface if [[ -n "${CONFIGURED_NIC}" ]]; then printf "This will delete the current configuration for ${CONFIGURED_NIC}.\n" - read -ep "Continue? (y/N) " - case $REPLY in - N|n) printf "\nAborting...\n"; return;; - esac + if ask_yes_or_no; then + printf "\nDeleting existing network configuration...\n" + else + printf "\nAborting...\n" + return + fi fi rm -rf $WORKDIR/* @@ -79,12 +81,9 @@ function configure_interface fi echo "NIC is: $NICSTATUS" - read -ep "Help identify $NIC by blinking lights for 10 seconds ([Y]es/[N]o)?" - case $REPLY in - Y|y) - ethtool --identify $NIC 10 - ;; - esac + if ask_yes_or_no "Help identify ${NIC} by blinking lights for 10 seconds (y/n)?"; then + ethtool --identify $NIC 10 + fi read -ep "Enable IPv4 support ([S]tatic IP, [D]HCP, [N]o or [A]bort)? " case $REPLY in @@ -129,18 +128,22 @@ function configure_interface esac printf "\n" - read -ep "Is this correct (Y/N/A)? " - case $REPLY in - Y|y) - IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" - BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" - - printf "$IF_CONFIG\n" > $IF_FILENAME - printf "$BR_CONFIG\n" > $BR_FILENAME - break + ask_yes_or_no "Is this correct (y/n/a)?" + case $? in + 0) + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" + printf "$IF_CONFIG\n" > $IF_FILENAME + printf "$BR_CONFIG\n" > $BR_FILENAME + break + ;; + 1) + BR_CONFIG=$BR_CONFIG_BASE + ;; + 2) + CONFIGURED_NIC="" + return ;; - N|n) BR_CONFIG=$BR_CONFIG_BASE ;; - A|a) CONFIGURED_NIC=""; return;; esac done else @@ -220,11 +223,11 @@ function configure_dns fi printf "\n" - read -ep "Is this correct (Y/N/A)? " - case $REPLY in - Y|y) break ;; - N|n) ;; - A|a) return ;; + ask_yes_or_no "Is this correct (y/n/a)?" + case $? in + 0) break ;; + 1) ;; + 2) return ;; esac done fi diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage index 41177a4..2e523df 100755 --- a/scripts/ovirt-config-storage +++ b/scripts/ovirt-config-storage @@ -208,11 +208,9 @@ do_configure() printf " partition should use up the remaining space on the disk.\n\n" do_review - read -ep "Use these default values? (Y/n) " - - case $REPLY in - Y|y) return;; - esac + if ask_yes_or_no "Use these default values (y/n)?"; then + return + fi local space_left=$SPACE for part in boot swap root config logging data ; do @@ -474,19 +472,15 @@ do_confirm() "$wb$sp$w" \ "$w8" \ "$w8" - printf "\n\tContinue? (Y/n) " - read -e - case $REPLY in - Y|y) - if check_partition_sizes; then - perform_partitioning - exit 0 - fi - break - ;; - N|n) return ;; - *) ;; - esac + + if ask_yes_or_no; then + if check_partition_sizes; then + perform_partitioning + exit 0 + fi + else + return + fi done } diff --git a/scripts/ovirt-config-uninstall b/scripts/ovirt-config-uninstall index 59661de..60ecf71 100755 --- a/scripts/ovirt-config-uninstall +++ b/scripts/ovirt-config-uninstall @@ -27,9 +27,7 @@ cat <<EOF EOF -read -ep "Do you wish to continue and uninstall this node (Y/N)? " - -if [ "$REPLY" == "Y" -o "$REPLY" == "y" ]; then +if ask_yes_or_no "Do you wish to continue and uninstall this node (y/n)?" if [ -d /dev/HostVG ]; then log "Uninstalling node" log "Detaching logging" diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions index e938256..09ddf50 100755 --- a/scripts/ovirt-functions +++ b/scripts/ovirt-functions @@ -627,6 +627,24 @@ chkconfig_persist() { ovirt_store_config $to_persist } +# Asks a yes or no question. Accepts Y/N/A so users can abort. +# RC=0 - Y/y entered +# RC=1 - N/n entered +# RC=2 - A/a entered +ask_yes_or_no () { + local prompt=${1-"Do you wish to proceed (y/n)?"} + + read -ep "${prompt} " + if [[ "${REPLY}" = "Y" ]] || [[ "${REPLY}" = "y" ]]; then + return 0 + elif [[ "${REPLY}" = "N" ]] || [[ "${REPLY}" = "n" ]]; then + return 1 + elif [[ "${REPLY}" = "A" ]] || [[ "${REPLY}" = "a" ]]; then + return 2 + else + return 99 + fi +} # execute a function if called as a script, e.g. # ovirt-functions ovirt_store_config /etc/hosts -- 1.6.2.5
Darryl L. Pierce
2009-Jul-07 17:58 UTC
[Ovirt-devel] Re: [PATCH node] Make all yes/no prompts consistent. rhbz#508778
On Tue, Jun 30, 2009 at 02:32:46PM -0400, Darryl L. Pierce wrote:> Added a new function, "ask_yes_or_no", to ovirt-functions. It contains a > default prompt if none is provided. > > Changed all prompts that ask for yes, no and/or abort to use this new > method. > > Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> > ---There are one or two patches in flight right now that'll need to be refactored slightly to accomodate these changes. -- Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc. Virtual Machine Management - http://www.ovirt.org/ Is fearr Gaeilge bhriste n? B?arla cliste. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20090707/b9705797/attachment.sig>
Joey Boggs
2009-Jul-09 20:17 UTC
[Ovirt-devel] [PATCH node] Make all yes/no prompts consistent. rhbz#508778
On 06/30/2009 02:32 PM, Darryl L. Pierce wrote:> Added a new function, "ask_yes_or_no", to ovirt-functions. It contains a > default prompt if none is provided. > > Changed all prompts that ask for yes, no and/or abort to use this new > method. > > Signed-off-by: Darryl L. Pierce<dpierce at redhat.com> > --- > scripts/ovirt-config-boot-wrapper | 8 ++--- > scripts/ovirt-config-collectd | 39 +++++++++++++++----------- > scripts/ovirt-config-logging | 45 ++++++++++++++++-------------- > scripts/ovirt-config-networking | 55 +++++++++++++++++++----------------- > scripts/ovirt-config-storage | 30 ++++++++------------ > scripts/ovirt-config-uninstall | 4 +-- > scripts/ovirt-functions | 18 ++++++++++++ > 7 files changed, 109 insertions(+), 90 deletions(-) > > diff --git a/scripts/ovirt-config-boot-wrapper b/scripts/ovirt-config-boot-wrapper > index ff6f6e5..4ce9969 100755 > --- a/scripts/ovirt-config-boot-wrapper > +++ b/scripts/ovirt-config-boot-wrapper > @@ -24,14 +24,12 @@ continuing." > else > bootparams="${OVIRT_BOOTPARAMS}" > fi > - read -p "Do you wish to continue (Y/n)? " > - r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]') > - if [ "$r" == "Y" ]; then > + if ask_yes_or_no; then > mount_live \ > -&& /usr/sbin/ovirt-config-boot /live "${bootparams}" > +&& /usr/sbin/ovirt-config-boot /live "${bootparams}" > rc=$? > break > - elif [ "$r" == "N" ]; then > + else > printf "\nExiting back to the menu\n" > rc=99 > break > diff --git a/scripts/ovirt-config-collectd b/scripts/ovirt-config-collectd > index 236ddaa..11811fd 100755 > --- a/scripts/ovirt-config-collectd > +++ b/scripts/ovirt-config-collectd > @@ -67,23 +67,28 @@ prompt_user() { > printf "\n" > printf "\n" > while true; do > - read -p "Is this correct (Y/N/A)? " > - r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]') > - if [ "$r" == "Y" ]; then > - printf "\nSaving configuration.\n" > - if [[ -n "$collectd_server_ip" ]]&& > - [[ -n "$collectd_server_port" ]]; then > - ovirt_collectd $collectd_server_ip \ > - $collectd_server_port > - fi > - return > - elif [ "$r" == "N" ]; then > - printf "\nRestarting collectd configuration.\n" > - break > - elif [ "$r" == "A" ]; then > - printf "\nAborting collectd configuration.\n" > - return > - fi > + ask_yes_or_no "Is this correct (y/n/a)?" > + rc=$? > + case $rc in > + 0) > + printf "\nSaving configuration.\n" > + if [[ -n "$collectd_server_ip" ]]&& > + [[ -n "$collectd_server_port" ]]; then > + ovirt_collectd $collectd_server_ip \ > + $collectd_server_port > + fi > + return > + ;; > + > + 1) > + printf "\nRestarting collectd configuration.\n" > + break > + ;; > + 2) > + printf "\nAborting collectd configuration.\n" > + return > + ;; > + esac > done > done > } > diff --git a/scripts/ovirt-config-logging b/scripts/ovirt-config-logging > index ba661c3..bb0f082 100755 > --- a/scripts/ovirt-config-logging > +++ b/scripts/ovirt-config-logging > @@ -146,27 +146,30 @@ function prompt_user { > printf "\n" > printf "\n" > while true; do > - read -p "Is this correct (Y/N/A)? " > - r=$(echo $REPLY|tr '[[:lower:]]' '[[:upper:]]') > - if [ "$r" == "Y" ]; then > - printf "\nSaving configuration.\n" > - if [[ -n "$syslog_server_ip" ]]&& > - [[ -n "$syslog_server_port" ]]&& > - [[ -n "$syslog_server_protocol" ]]; then > - ovirt_rsyslog $syslog_server_ip \ > - $syslog_server_port \ > - $syslog_server_protocol > - fi > - sed -c -i -e "s/^size=.*/size=${max_log_size}k/" \ > - /etc/logrotate.d/ovirt-logrotate.conf > - return > - elif [ "$r" == "N" ]; then > - printf "\nRestarting logging configuration.\n" > - break > - elif [ "$r" == "A" ]; then > - printf "\nAborting logging configuration.\n" > - return > - fi > + ask_yes_or_no "Is this correct (y/n/a)?" > + case $? in > + 0) > + printf "\nSaving configuration.\n" > + if [[ -n "$syslog_server_ip" ]]&& > + [[ -n "$syslog_server_port" ]]&& > + [[ -n "$syslog_server_protocol" ]]; then > + ovirt_rsyslog $syslog_server_ip \ > + $syslog_server_port \ > + $syslog_server_protocol > + fi > + sed -c -i -e "s/^size=.*/size=${max_log_size}k/" \ > + /etc/logrotate.d/ovirt-logrotate.conf > + return > + ;; > + 1) > + printf "\nRestarting logging configuration.\n" > + break > + ;; > + 2) > + printf "\nAborting logging configuration.\n" > + return > + ;; > + esac > done > done > } > diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking > index d29bd12..713cabc 100755 > --- a/scripts/ovirt-config-networking > +++ b/scripts/ovirt-config-networking > @@ -40,10 +40,12 @@ function configure_interface > > if [[ -n "${CONFIGURED_NIC}" ]]; then > printf "This will delete the current configuration for ${CONFIGURED_NIC}.\n" > - read -ep "Continue? (y/N) " > - case $REPLY in > - N|n) printf "\nAborting...\n"; return;; > - esac > + if ask_yes_or_no; then > + printf "\nDeleting existing network configuration...\n" > + else > + printf "\nAborting...\n" > + return > + fi > fi > > rm -rf $WORKDIR/* > @@ -79,12 +81,9 @@ function configure_interface > fi > echo "NIC is: $NICSTATUS" > > - read -ep "Help identify $NIC by blinking lights for 10 seconds ([Y]es/[N]o)?" > - case $REPLY in > - Y|y) > - ethtool --identify $NIC 10 > - ;; > - esac > + if ask_yes_or_no "Help identify ${NIC} by blinking lights for 10 seconds (y/n)?"; then > + ethtool --identify $NIC 10 > + fi > > read -ep "Enable IPv4 support ([S]tatic IP, [D]HCP, [N]o or [A]bort)? " > case $REPLY in > @@ -129,18 +128,22 @@ function configure_interface > esac > > printf "\n" > - read -ep "Is this correct (Y/N/A)? " > - case $REPLY in > - Y|y) > - IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" > - BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" > - > - printf "$IF_CONFIG\n"> $IF_FILENAME > - printf "$BR_CONFIG\n"> $BR_FILENAME > - break > + ask_yes_or_no "Is this correct (y/n/a)?" > + case $? in > + 0) > + IF_CONFIG="$IF_CONFIG\nset $IF_ROOT/ONBOOT yes" > + BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/ONBOOT yes" > + printf "$IF_CONFIG\n"> $IF_FILENAME > + printf "$BR_CONFIG\n"> $BR_FILENAME > + break > + ;; > + 1) > + BR_CONFIG=$BR_CONFIG_BASE > + ;; > + 2) > + CONFIGURED_NIC="" > + return > ;; > - N|n) BR_CONFIG=$BR_CONFIG_BASE ;; > - A|a) CONFIGURED_NIC=""; return;; > esac > done > else > @@ -220,11 +223,11 @@ function configure_dns > fi > > printf "\n" > - read -ep "Is this correct (Y/N/A)? " > - case $REPLY in > - Y|y) break ;; > - N|n) ;; > - A|a) return ;; > + ask_yes_or_no "Is this correct (y/n/a)?" > + case $? in > + 0) break ;; > + 1) ;; > + 2) return ;; > esac > done > fi > diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage > index 41177a4..2e523df 100755 > --- a/scripts/ovirt-config-storage > +++ b/scripts/ovirt-config-storage > @@ -208,11 +208,9 @@ do_configure() > printf " partition should use up the remaining space on the disk.\n\n" > > do_review > - read -ep "Use these default values? (Y/n) " > - > - case $REPLY in > - Y|y) return;; > - esac > + if ask_yes_or_no "Use these default values (y/n)?"; then > + return > + fi > > local space_left=$SPACE > for part in boot swap root config logging data ; do > @@ -474,19 +472,15 @@ do_confirm() > "$wb$sp$w" \ > "$w8" \ > "$w8" > - printf "\n\tContinue? (Y/n) " > - read -e > - case $REPLY in > - Y|y) > - if check_partition_sizes; then > - perform_partitioning > - exit 0 > - fi > - break > - ;; > - N|n) return ;; > - *) ;; > - esac > + > + if ask_yes_or_no; then > + if check_partition_sizes; then > + perform_partitioning > + exit 0 > + fi > + else > + return > + fi > done > } > > diff --git a/scripts/ovirt-config-uninstall b/scripts/ovirt-config-uninstall > index 59661de..60ecf71 100755 > --- a/scripts/ovirt-config-uninstall > +++ b/scripts/ovirt-config-uninstall > @@ -27,9 +27,7 @@ cat<<EOF > > EOF > > -read -ep "Do you wish to continue and uninstall this node (Y/N)? " > - > -if [ "$REPLY" == "Y" -o "$REPLY" == "y" ]; then > +if ask_yes_or_no "Do you wish to continue and uninstall this node (y/n)?" > if [ -d /dev/HostVG ]; then > log "Uninstalling node" > log "Detaching logging" > diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions > index e938256..09ddf50 100755 > --- a/scripts/ovirt-functions > +++ b/scripts/ovirt-functions > @@ -627,6 +627,24 @@ chkconfig_persist() { > ovirt_store_config $to_persist > } > > +# Asks a yes or no question. Accepts Y/N/A so users can abort. > +# RC=0 - Y/y entered > +# RC=1 - N/n entered > +# RC=2 - A/a entered > +ask_yes_or_no () { > + local prompt=${1-"Do you wish to proceed (y/n)?"} > + > + read -ep "${prompt} " > + if [[ "${REPLY}" = "Y" ]] || [[ "${REPLY}" = "y" ]]; then > + return 0 > + elif [[ "${REPLY}" = "N" ]] || [[ "${REPLY}" = "n" ]]; then > + return 1 > + elif [[ "${REPLY}" = "A" ]] || [[ "${REPLY}" = "a" ]]; then > + return 2 > + else > + return 99 > + fi > +} > > # execute a function if called as a script, e.g. > # ovirt-functions ovirt_store_config /etc/hosts >ack
Possibly Parallel Threads
- [PATCH node] validify ipv4/ipv6 static/dhcp choice else loop
- [PATCH node] Adds vlan support to auto-installations for the node. bz#511056
- [PATCH node] add network.py script
- [PATCH node] Rerunning network config resets all network config. bz#507393
- [PATCH node] REPOST Joey's and Darryl's ovirt-config-* patches