diff --git a/Scripts/Bash/Functions/Commons/cli_getConfigLines.sh b/Scripts/Bash/Functions/Commons/cli_getConfigLines.sh index ce93e73..0e460f5 100755 --- a/Scripts/Bash/Functions/Commons/cli_getConfigLines.sh +++ b/Scripts/Bash/Functions/Commons/cli_getConfigLines.sh @@ -1,9 +1,9 @@ #!/bin/bash # -# cli_getConfigLines.sh -- This function retrives configuration lines -# form configuration files. As arguments, the configuration file -# absolute path, the configuration section name, and the configuration -# variable name must be provided. +# cli_getConfigLines.sh -- This function standardizes the way +# configuration lines are retrieved form configuration files. As +# arguments, the configuration file absolute path, the configuration +# section name, and the configuration option name must be provided. # # Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project # @@ -34,28 +34,33 @@ function cli_getConfigLines { cli_checkFiles -e ${CONFIG_ABSPATH} # Initialize configuration section name where the variable value - # we want to to retrive is set in. + # we want to to retrieve is set in. local CONFIG_SECTION="$2" - # Initialize variable name we want to retrive value from. - local CONFIG_VARNAME="$3" + # Be sure the configuration section name has the correct format. + if [[ ! $CONFIG_SECTION =~ '^[[:alpha:]]+$' ]];then + cli_printMessage "`gettext "The configuration section provided is incorrect."`" --as-error-line + fi + + # Initialize variable name we want to retrieve value from. + local CONFIG_OPTION="$3" # Verify configuration variable name. When no variable name is - # provided print all configuration lines that can be considered - # as well-formed paths. Be sure configuration variable name starts - # just at the begining of the line. - if [[ ! $CONFIG_VARNAME =~ '^[[:alnum:]_./-]+$' ]];then - CONFIG_VARNAME='[[:alnum:]_./-]+=' + # provided print all configuration lines that can be considered as + # well-formed paths. Be sure configuration variable name starts + # just at the beginning of the line. + if [[ ! $CONFIG_OPTION =~ '^[[:alnum:]_./-]+$' ]];then + CONFIG_OPTION='[[:alnum:]_./-]+=' fi - # Retrive configuration lines from configuration file. + # Retrieve configuration lines from configuration file. local CONFIG_LINES=$(cat ${CONFIG_ABSPATH} \ | egrep -v '^#' \ | egrep -v '^[[:space:]]*$' \ | sed -r 's![[:space:]]*!!g' \ | sed -r -n "/^\[${CONFIG_SECTION}\]$/,/^\[/p" \ | egrep -v '^\[' | sort | uniq \ - | egrep "^${CONFIG_VARNAME}") + | egrep "^${CONFIG_OPTION}") # Output value related to variable name. echo "$CONFIG_LINES"