Check for releasever in yum.conf before grepping

The dl_rpms.sh script may be passed an optional yum.conf file.  If
this file is used, then the releasever variable is read from the
rather than use the default releasever=7.  If the releasever is
not defined in the file, the grep which searches for the variable
will fail, and the dl_rpms.sh script exits with an error.

This change checks for the presence of releasever before attempting
to read it from the file.  Change made to dl_rpms.sh and
mirror-check.sh

Tested using yum.conf files both with and without releasever
present.

Change-Id: Ie13241e5662188d75b5d147537915c0a35ea7397
Closes-Bug: 1791113
Signed-off-by: Jason McKenna <jason.mckenna@windriver.com>
This commit is contained in:
Jason McKenna 2018-09-06 10:52:09 -04:00
parent f5048fd3c7
commit d56955c5f1
2 changed files with 2 additions and 2 deletions

View File

@ -60,7 +60,7 @@ while getopts "c:nxh" o; do
c)
# Use an alternate yum.conf
YUMCONFOPT="-c $OPTARG"
RELEASEVER="--$(grep releasever= ${OPTARG})"
grep -q "releasever=" $OPTARG && RELEASEVER="--$(grep releasever= ${OPTARG})"
;;
h)
# Help

View File

@ -115,7 +115,7 @@ while getopts "c:" opt; do
case $opt in
c)
extra_opts="-c ${OPTARG}"
RELEASEVER="--$(grep releasever= ${OPTARG})"
grep -q "releasever=" $OPTARG && RELEASEVER="--$(grep releasever= ${OPTARG})"
;;
\?)
echo "Invalid option: -$OPTARG" >&2