Skip to content

Commit

Permalink
fix(dracut-functions): avoid awk in get_maj_min()
Browse files Browse the repository at this point in the history
The `get_maj_min()` cache lookup is commonly used
across many flows. While `awk` should be available,
some highly constrained environments may not have it.
A second call to `grep` can provide the same behaviour
without adding a dependnecy.

Lines in the cache will be of the form "/dev/sda2 8:2".
`awk '{print $NF}'` returns the last word of a matching line. Since
the initial matching regex is so specific a second call to grep can
easily extract the last word.

(cherry picked commit ec7efd5)

Related: RHEL-47145
  • Loading branch information
dmcilvaney authored and pvalena committed Aug 19, 2024
1 parent e1ae840 commit d18bbc3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dracut-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ get_maj_min() {
local _out
if [[ $get_maj_min_cache_file ]]; then
_out="$(grep -m1 -oE "^${1//\\/\\\\} \S+$" "$get_maj_min_cache_file" | awk '{print $NF}')"
_out="$(grep -m1 -oE "^${1//\\/\\\\} \S+$" "$get_maj_min_cache_file" | grep -oE "\S+$")"
fi
if ! [[ "$_out" ]]; then
Expand Down

0 comments on commit d18bbc3

Please sign in to comment.