Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions bash/patchman-client
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cleanup() {
echo "Debug: not deleting ${tmpfile_sec} (security updates)"
echo "Debug: not deleting ${tmpfile_bug} (updates)"
echo "Debug: not deleting ${tmpfile_mod} (modules)"
if [ ! -z "${tmpfile_packages_json}" ] ; then
if [ -n "${tmpfile_packages_json}" ] ; then
echo "Debug: not deleting ${tmpfile_packages_json} (packages json)"
echo "Debug: not deleting ${tmpfile_repos_json} (repos json)"
echo "Debug: not deleting ${tmpfile_modules_json} (modules json)"
Expand Down Expand Up @@ -122,7 +122,7 @@ cleanup() {
}

check_conf() {
if [ ! -z "${cli_conf}" ] ; then
if [ -n "${cli_conf}" ] ; then
conf=${cli_conf}
fi

Expand All @@ -148,7 +148,7 @@ check_conf() {
echo " Edit ${conf} and set server= to your patchman server URL." >&2
exit 1
fi
if [ ! -z "${cli_server}" ] ; then
if [ -n "${cli_server}" ] ; then
server=${cli_server}
fi
if echo "${server}" | grep -qE 'patchman\.example\.com' ; then
Expand All @@ -157,31 +157,31 @@ check_conf() {
exit 1
fi
else
if [ ! -z "${cli_server}" ] ; then
if [ -n "${cli_server}" ] ; then
server=${cli_server}
fi
fi

if [ ! -z "${cli_report}" ] ; then
if [ -n "${cli_report}" ] ; then
report=${cli_report}
fi

if [ ! -z "${cli_tags}" ] ; then
if [ -n "${cli_tags}" ] ; then
tags="${cli_tags}"
fi

if [ ! -z "${cli_protocol}" ] ; then
if [ -n "${cli_protocol}" ] ; then
protocol=${cli_protocol}
fi

if [ ! -z "${cli_api_key}" ] ; then
if [ -n "${cli_api_key}" ] ; then
api_key=${cli_api_key}
fi

if [ -z "${hostname}" ] && [ -z "${cli_hostname}" ] ; then
get_hostname
else
if [ ! -z "${cli_hostname}" ] ; then
if [ -n "${cli_hostname}" ] ; then
hostname=${cli_hostname}
fi
fi
Expand All @@ -205,7 +205,7 @@ check_conf() {
echo "Hostname: ${hostname}"
echo "Tags: ${tags}"
echo "Protocol: ${protocol}"
if [ ! -z "${api_key}" ] ; then
if [ -n "${api_key}" ] ; then
echo "API Key: ${api_key:0:12}..."
fi
for var in report local_updates repo_check dry_run verbose debug ; do
Expand Down Expand Up @@ -258,7 +258,7 @@ parse_module() {
module_package_str="${module_package_str} '${package}'"
done
IFS=${FULL_IFS}
if [ ! -z ${CPE_NAME} ] ; then
if [ -n "${CPE_NAME}" ] ; then
module_repo="${CPE_NAME}-${module_repo}"
fi
echo "'${module}' '${module_stream}' '${module_version}' '${module_context}' '${module_arch}' '${module_repo}'${module_package_str}" >> ${tmpfile_mod}
Expand Down Expand Up @@ -383,7 +383,7 @@ get_hostname() {
short_hostname=$(cat /etc/hostname)
fi
domainname=$(dnsdomainname)
if [ ! -z "${domainname}" ] ; then
if [ -n "${domainname}" ] ; then
hostname=${short_hostname}.${domainname}
else
hostname=${short_hostname}
Expand All @@ -398,7 +398,7 @@ get_host_data() {
if [ -f /etc/os-release ] ; then
. /etc/os-release
if [ "${ID}" == "debian" ] ; then
os="Debian $(cat /etc/debian_version | sed -e 's/\//-/')"
os="Debian $(sed -e 's/\//-/' /etc/debian_version)"
elif [ "${ID}" == "raspbian" ] ; then
os="Raspbian $(cat /etc/debian_version)"
elif [ "${ID}" == "ubuntu" ] ; then
Expand Down Expand Up @@ -453,7 +453,7 @@ get_host_data() {
fi
done
fi
if [ ! -z "${CPE_NAME}" ] ; then
if [ -n "${CPE_NAME}" ] ; then
os="${os} [${CPE_NAME}]"
fi
if ${verbose} ; then
Expand Down Expand Up @@ -495,7 +495,7 @@ get_yum_updates() {
| grep -v 'Failed to set locale' \
>> "${tmpfile_bug}"
sed -i '/^$/d' "${tmpfile_bug}"
if [ ! -z ${CPE_NAME} ] ; then
if [ -n "${CPE_NAME}" ] ; then
sed -i -e "s#${1}#${CPE_NAME}-${1}#g" "${tmpfile_sec}"
sed -i -e "s#${1}#${CPE_NAME}-${1}#g" "${tmpfile_bug}"
fi
Expand Down Expand Up @@ -565,7 +565,7 @@ get_repos() {
fi
get_yum_updates ${id}
fi
if [ ! -z ${CPE_NAME} ] ; then
if [ -n "${CPE_NAME}" ] ; then
id="${CPE_NAME}-${id}"
fi
j=$(echo ${i} | sed -e "s#'${full_id}' '${orig_name}'#'${name}' '${id}' '${priority}'#" | sed -e "s/'\[/'/g" -e "s/\]'/'/g")
Expand Down Expand Up @@ -945,7 +945,7 @@ build_json_report() {

# Convert tags to JSON array
local tags_json="[]"
if [ ! -z "${tags}" ] && [ "${tags}" != "Default" ] ; then
if [ -n "${tags}" ] && [ "${tags}" != "Default" ] ; then
tags_json=$(echo "${tags}" | tr ',' '\n' | jq -R . | jq -s .)
fi

Expand Down Expand Up @@ -1012,7 +1012,7 @@ post_json_data() {
fi

curl_opts="${curl_opts} -H 'Content-Type: application/json'"
if [ ! -z "${api_key}" ] ; then
if [ -n "${api_key}" ] ; then
curl_opts="${curl_opts} -H 'Authorization: Api-Key ${api_key}'"
fi
curl_opts="${curl_opts} -d @${tmpfile_report_json}"
Expand All @@ -1032,7 +1032,7 @@ post_json_data() {
fi

if ${report} || ${verbose} ; then
if [ ! -z "${result}" ] ; then
if [ -n "${result}" ] ; then
echo "${result}" | jq . 2>/dev/null || echo "${result}"
else
echo "No output returned."
Expand Down Expand Up @@ -1084,7 +1084,7 @@ post_data() {
fi

if ${report} || ${verbose} ; then
if [ ! -z "${result}" ] ; then
if [ -n "${result}" ] ; then
echo "${result}"
else
echo "No output returned."
Expand Down Expand Up @@ -1150,7 +1150,7 @@ if ${dry_run} ; then
echo "Security updates: $(wc -l < ${tmpfile_sec})"
echo "Bugfix updates: $(wc -l < ${tmpfile_bug})"
echo "Reboot required: ${reboot}"
if [ ! -z "${tags}" ] ; then
if [ -n "${tags}" ] ; then
echo "Tags: ${tags}"
fi
if ${verbose} ; then
Expand Down
1 change: 1 addition & 0 deletions python/README.md
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "patchman-client"
dynamic = ["version"]
description = "Patchman client for reporting system packages and updates"
readme = {file = "../README.md", content-type = "text/markdown"}
readme = {file = "README.md", content-type = "text/markdown"}
license = "GPL-3.0-or-later"
authors = [
{name = "Marcus Furlong", email = "furlongm@gmail.com"}
Expand Down
3 changes: 1 addition & 2 deletions tests/test_client_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ class YumRepolistAwkTests(unittest.TestCase):
"""

AWK_CMD = (
r"""awk 'BEGIN{n=0} { if ($1=="Repo-id") {if(n>0){print ""} n++; url=0; printf "'"'"'"; for (i=3; i<NF; i++) printf $i " "; printf $NF"'"'"' "} if ($1=="Repo-name") {printf "'"'"'"; for (i=3; i<NF; i++) printf $i " "; printf $NF"'" x86_64'"' "} if ($1=="Repo-mirrors" || $1=="Repo-metalink") {printf "'"'"'"; for (i=3; i<NF; i++) printf $i " "; printf $NF"'"'"' "} if ($1=="Repo-baseurl" || $1=="Repo-baseurl:") { url=1; comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"'"'"out"'"'"' "; } else { if (url==1) { if ($1==":") { comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"'"'"out"'"'"' "; } else {url=0} } } } END{if(n>0) print ""}'"""
r"""awk 'BEGIN{n=0} { if ($1=="Repo-id") {if(n>0){print ""} n++; url=0; printf "'"'"'"; for (i=3; i<NF; i++) printf $i " "; printf $NF"'"'"' "} if ($1=="Repo-name") {printf "'"'"'"; for (i=3; i<NF; i++) printf $i " "; printf $NF"'" x86_64'"' "} if ($1=="Repo-mirrors" || $1=="Repo-metalink") {printf "'"'"'"; for (i=3; i<NF; i++) printf $i " "; printf $NF"'"'"' "} if ($1=="Repo-baseurl" || $1=="Repo-baseurl:") { url=1; comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"'"'"out"'"'"' "; } else { if (url==1) { if ($1==":") { comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"'"'"out"'"'"' "; } else {url=0} } } } END{if(n>0) print ""}'""" # noqa: E501
)

def _run_awk(self, input_text):
Expand Down Expand Up @@ -1056,7 +1056,6 @@ class PythonClientYumRepoTests(unittest.TestCase):

def _collect(self, yum_output, arch='x86_64'):
"""Create a PatchmanClient, mock yum output, and collect repos."""
from unittest.mock import patch, PropertyMock
import sys
sys.path.insert(0, os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
Expand Down
Loading