On Wed, 2010-03-24 at 15:18 -0400, Darryl L. Pierce wrote: > Checks any entered address for DNS and NTP servers against previously > entered ones in order to prevent duplicates. > > Resolves: rhbz#555373 > > Signed-off-by: Darryl L. Pierce <[email protected]> > --- > scripts/ovirt-config-networking | 47 +++++++++++++++++++++++++------------- > scripts/ovirt-functions | 7 +++++ > 2 files changed, 38 insertions(+), 16 deletions(-) > > diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking > index 6c2bd21..4d412ac 100755 > --- a/scripts/ovirt-config-networking > +++ b/scripts/ovirt-config-networking > @@ -357,8 +357,9 @@ function configure_dns > for dns in first second; do > while true; do > printf "\n" > - read -ep "Please enter the ${dns} DNS server (or > ENTER to exit): " > - if [[ -z "${REPLY}" ]]; then > + read -erp "Please enter the ${dns} DNS server (or > ENTER to exit): " > + local ADDRESS=$(trim_whitespace $REPLY) > + if [[ -z "${ADDRESS}" ]]; then > if [[ -z "${DNS}" ]]; then > printf "\nAborted...\n" > return > @@ -366,15 +367,20 @@ function configure_dns > break > fi > fi > - if is_valid_ipv4 $REPLY; then > + if is_valid_ipv4 $ADDRESS; then > if [[ -z "${DNS}" ]]; then > - DNS="${REPLY}" > - elif [[ -n "${REPLY}" ]]; then > - DNS="${DNS}:${REPLY}" > + DNS="${ADDRESS}" > + break > + elif [[ -n "${ADDRESS}" ]]; then > + if [[ ! $DNS =~ "${ADDRESS}" ]]; then > + DNS="${DNS}:${ADDRESS}" > + break > + else > + printf "${ADDRESS} is already defined as > a DNS server.\n" > + fi > fi > - break > else > - printf "${REPLY} is an invalid address.\n" > + printf "${ADDRESS} is an invalid address.\n" > fi > done > done > @@ -403,19 +409,28 @@ function configure_ntp > { > local AUTO=$2 > if [[ "$AUTO" == "AUTO" && -n "$OVIRT_NTP" ]]; then > - NTPSERVERS=$OVIRT_NTP > + NTPSERVERS=$OVIRT_NTP > else > - NTPSERVERS="" > + NTPSERVERS="" > fi > > if [ -z "$AUTO" ]; then > if has_configured_interface true; then > - while true; do > - read -ep "Enter an NTP server (hit return when finished): " > + while true; do > + read -rp "Enter an NTP server (hit return when finished): " > + local ADDRESS=$(trim_whitespace $REPLY) > > - if [ -z "$REPLY" ]; then break; fi > - NTPSERVERS="${NTPSERVERS}:${REPLY}" > - done > + if [ -z "${ADDRESS}" ]; then break; fi > + if is_valid_ipv4 $ADDRESS; then > + if [[ ! $NTPSERVERS =~ $ADDRESS ]]; then > + NTPSERVERS="${NTPSERVERS}:${ADDRESS}" > + else > + printf "${ADDRESS} is already defined as an NTP > server.\n" > + fi > + else > + printf "${ADDRESS} is an invalid address.\n" > + fi > + done > fi > fi > } > diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions > index 482441a..d8aa008 100644 > --- a/scripts/ovirt-functions > +++ b/scripts/ovirt-functions > @@ -665,6 +665,13 @@ add_if_not_exist() { > || echo "$string" >> "$file" > } > > +# $1 - the string to be trimmed > +trim_whitespace () { > + local text=${1} > + > + printf "$text" | awk '{gsub(/^[ ]*/,"",$0); gsub(/[ ]*$/,"",$0) ; print > }' > +} > + > is_numeric() { > printf "$1" | grep -q -E '^[0-9]+$' > }
ACK _______________________________________________ Ovirt-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/ovirt-devel
