Changed to use sed for regex pattern matching

The code was using a mixture of shell patterns and
sed regular expression. Changed code to just used
sed regex. This will let me use more complex regex
that are needed for adding PARTUUID to uuids.

BUG=chromium:241572
TEST=./security_test_image
BRANCH=none

Change-Id: I2e8570051b31d580ae36cb82f05383a33236b88e
Reviewed-on: https://gerrit.chromium.org/gerrit/51503
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Paul Taysom <taysom@chromium.org>
Tested-by: Paul Taysom <taysom@chromium.org>
This commit is contained in:
Paul Taysom
2013-05-16 14:27:09 -07:00
committed by ChromeBot
parent ed92adaddf
commit 01bc003cff

View File

@@ -65,6 +65,8 @@ main() {
local testfail=0 local testfail=0
# A buffer to include useful information that we dump when things fail. # A buffer to include useful information that we dump when things fail.
local output local output
# Copy of a string before it has been through sed
local pre_sed
if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
usage usage
@@ -170,15 +172,12 @@ main() {
# Ensure all other required regex params are present. # Ensure all other required regex params are present.
for param in "${required_kparams_regex[@]}"; do for param in "${required_kparams_regex[@]}"; do
if [[ "$kparams_nodm" != *$param* ]]; then pre_sed=" ${kparams_nodm} "
echo "Kernel parameters missing required value: $param" kparams_nodm=$(echo "${pre_sed}" | sed "s${M} ${param} ${M} ${M}")
testfail=1 if [[ "${pre_sed}" == "${kparams_nodm}" ]]; then
else echo "Kernel parameters missing required value: ${param}"
# Remove matched params as we go. If all goes well, kparams_nodm testfail=1
# will be nothing left but whitespace by the end. fi
kparams_nodm=$(echo " ${kparams_nodm} " |
sed "s${M} ${param} ${M} ${M}")
fi
done done
# Check-off each of the allowed-but-optional params that were present. # Check-off each of the allowed-but-optional params that were present.