From d56955c5f1d2f16e14ee0d033819c498ce092afe Mon Sep 17 00:00:00 2001 From: Jason McKenna Date: Thu, 6 Sep 2018 10:52:09 -0400 Subject: [PATCH] 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 --- centos-mirror-tools/dl_rpms.sh | 2 +- centos-mirror-tools/mirror-check.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/centos-mirror-tools/dl_rpms.sh b/centos-mirror-tools/dl_rpms.sh index 67cf7924..5fd66eef 100755 --- a/centos-mirror-tools/dl_rpms.sh +++ b/centos-mirror-tools/dl_rpms.sh @@ -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 diff --git a/centos-mirror-tools/mirror-check.sh b/centos-mirror-tools/mirror-check.sh index 43a92a17..919cfb80 100755 --- a/centos-mirror-tools/mirror-check.sh +++ b/centos-mirror-tools/mirror-check.sh @@ -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