Skip to content

Commit

Permalink
Merge pull request #594 from furlongm/modules-fix
Browse files Browse the repository at this point in the history
fix module parsing on rhel 8 and similar
  • Loading branch information
furlongm authored Jun 23, 2024
2 parents 5107b64 + ce840e4 commit 7a919e5
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions client/patchman-client
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

export LC_ALL=C
export FULL_IFS=$' \t\n'
export NL_IFS=$'\n'

conf=/etc/patchman/patchman-client.conf
protocol=1
Expand Down Expand Up @@ -191,30 +193,36 @@ get_enabled_modules() {
if ${verbose} ; then
echo 'Finding enabled yum modules...'
fi

enabled_modules=$(yum module list --enabled \
| grep "\[e\]" \
| grep -v ^Hint \
| awk {'print $1'})

OLDIFS=${IFS}
IFS="
"
for module in ${enabled_modules} ; do
IFS=${OLDIFS}
module_info=$(yum module info ${module})
module_arch=$(echo ${module_info} | grep Architecture | cut -d : -f 2 | awk '{$1=$1};1')
module_repo=$(echo ${module_info} | grep Repo | cut -d : -f 2 | awk '{$1=$1};1')
module_stream=$(echo ${module_info} | grep Stream | cut -d : -f 2 | sed -e 's/ \[.*//g' | awk '{$1=$1};1')
module_version=$(echo ${module_info} | grep Version | cut -d : -f 2 | awk '{$1=$1};1')
module_context=$(echo ${module_info} | grep Context | cut -d : -f 2 | awk '{$1=$1};1')
module_packages=$(echo ${module_info} | sed -n '/Artifacts/,$p' | grep -v Hint | sed -e 's/.* : //g' | grep -v ^$)
OLDIFS=${IFS}
IFS="
"
modules_info=$(yum module info ${module} | grep -v ^Hint)
unset x
while read -r line ; do
if [ -z "$line" ] ; then
echo -e ${x} | grep -q -E "^Stream.*\[e\]" && break || unset x
else
x="$x$line\n"
fi
done < <(echo -n "${modules_info}")
module_info=$(echo -e ${x})
module_arch=$(echo "${module_info}" | grep ^Architecture | cut -d : -f 2 | awk '{$1=$1};1')
module_repo=$(echo "${module_info}" | grep ^Repo | cut -d : -f 2 | awk '{$1=$1};1')
module_stream=$(echo "${module_info}" | grep ^Stream | cut -d : -f 2 | sed -e 's/ \[.*//g' | awk '{$1=$1};1')
module_version=$(echo "${module_info}" | grep ^Version | cut -d : -f 2 | awk '{$1=$1};1')
module_context=$(echo "${module_info}" | grep ^Context | cut -d : -f 2 | awk '{$1=$1};1')
module_packages=$(echo "${module_info}" | sed -n '/Artifacts/,$p' | sed -e 's/.* *: //g' | grep -v ^$)

IFS=${NL_IFS}
module_package_str=""
for package in ${module_packages} ; do
module_package_str="${module_package_str} '${package}'"
done
IFS=${OLDIFS}
IFS=${FULL_IFS}
echo "'${module}' '${module_stream}' '${module_version}' '${module_context}' '${module_arch}' '${module_repo}' ${module_package_str}" >> ${tmpfile_mod}
done
if [ ! -z ${CPE_NAME} ] ; then
Expand Down Expand Up @@ -275,16 +283,13 @@ AWK
cat "${tmpfile_pkg}"
fi
fi
IFS=${OLDIFS}
}

get_installed_archlinux_packages() {
if check_command_exists pacman ; then
OLDIFS=${IFS}
IFS="
"
IFS=${NL_IFS}
pacman -Q -i | awk -v q="'" -v s=" " '/^Name/{n=$3} /^Version/{l=split($3, e, ":"); if (l==2) {ep=e[1]; v=e[2]} else {ep=""; v=$3}; split(v, r, "-")} /^Architecture/{a=$3} /^$/{print q n q s q ep q s q r[1] q s q r[2] q s q a q s q"arch"q}' >> "${tmpfile_pkg}"
IFS=${OLDIFS}
IFS=${FULL_IFS}
fi
}

Expand Down Expand Up @@ -427,9 +432,7 @@ get_zypper_updates() {
}

get_repos() {
OLDIFS=${IFS}
IFS="
"
IFS=${NL_IFS}

# Red Hat / CentOS
if check_command_exists yum ; then
Expand Down Expand Up @@ -475,7 +478,7 @@ get_repos() {
if ${verbose} ; then
echo 'Finding apt repos...'
fi
IFS=${OLDIFS} read -r osname shortversion <<<$(echo "${os}" | awk '{print $1,$2}' | cut -d . -f 1,2)
IFS=${FULL_IFS} read -r osname shortversion <<<$(echo "${os}" | awk '{print $1,$2}' | cut -d . -f 1,2)
repo_string="'deb\' \'${osname} ${shortversion} ${host_arch} repo at"
repos=$(apt-cache policy | grep -v Translation | grep -E "^ *[0-9]{1,5}" | grep -E " mirror\+file|http(s)?:" | sed -e "s/^ *//g" -e "s/ *$//g" | cut -d " " -f 1,2,3,4)
non_mirror_repos=$(echo "${repos}" | grep -Ev "mirror\+file")
Expand Down Expand Up @@ -543,7 +546,7 @@ get_repos() {
done
fi

IFS=${OLDIFS}
IFS=${FULL_IFS}

sed -i -e '/^$/d' "${tmpfile_rep}"

Expand Down

0 comments on commit 7a919e5

Please sign in to comment.