Skip to content

Commit 8102396

Browse files
committed
client updates
1 parent ca04746 commit 8102396

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

client/patchman-client

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,7 @@ check_booleans() {
210210
}
211211

212212
check_command_exists() {
213-
cmd=$(/usr/bin/which ${1} 2>/dev/null)
214-
if [ ! -z "${cmd}" ] && [ -x "${cmd}" ] ; then
215-
return 0
216-
else
217-
return 1
218-
fi
213+
command -v "${1}" >/dev/null 2>&1
219214
}
220215

221216
check_for_modularity() {
@@ -514,6 +509,8 @@ get_repos() {
514509
full_id=$(echo ${i} | cut -d \' -f 2)
515510
id=$(echo ${i} | cut -d \' -f 2 | cut -d \/ -f 1)
516511
name=$(echo ${i} | cut -d \' -f 4)
512+
# Strip " - arch arch" suffix pattern to avoid duplicates like "EPEL - x86_64 x86_64"
513+
name=$(echo "${name}" | sed -e "s/ - ${host_arch} ${host_arch}$/ ${host_arch}/")
517514
if [ "${priorities}" != "" ] ; then
518515
priority=$(echo "${priorities}" | grep "'${name}'" | sed -e "s/priority=\(.*\) '${name}'/\1/")
519516
fi
@@ -748,21 +745,34 @@ build_repos_json() {
748745
if [ -z "${line}" ] ; then
749746
continue
750747
fi
751-
# Parse: 'type' 'name' 'id' 'priority' 'url1' ['url2' ...]
748+
# Parse quoted fields from line
752749
local parts=()
753750
while IFS= read -r part ; do
754751
parts+=("${part}")
755752
done < <(echo "${line}" | grep -oP "'[^']*'" | tr -d "'")
756753

757754
local rtype="${parts[0]}"
758755
local name="${parts[1]}"
759-
local rid="${parts[2]}"
760-
local priority="${parts[3]}"
756+
local rid=""
757+
local priority=""
758+
local url_start=0
759+
760+
# APT repos have 4 fields: 'type' 'name' 'priority' 'url'
761+
# Other repos have 5+ fields: 'type' 'name' 'id' 'priority' 'url1' ...
762+
if [ "${rtype}" == "deb" ] ; then
763+
rid=""
764+
priority="${parts[2]}"
765+
url_start=3
766+
else
767+
rid="${parts[2]}"
768+
priority="${parts[3]}"
769+
url_start=4
770+
fi
761771

762772
# Collect URLs (all remaining parts)
763773
local urls_json="["
764774
local url_first=true
765-
for ((i=4; i<${#parts[@]}; i++)); do
775+
for ((i=${url_start}; i<${#parts[@]}; i++)); do
766776
if ! ${url_first} ; then
767777
urls_json="${urls_json},"
768778
fi
@@ -1033,12 +1043,11 @@ post_data() {
10331043
fi
10341044
}
10351045

1036-
if ! check_command_exists which || \
1037-
! check_command_exists awk || \
1046+
if ! check_command_exists awk || \
10381047
! check_command_exists mktemp || \
10391048
! check_command_exists curl || \
10401049
! check_command_exists flock ; then
1041-
echo "which, awk, mktemp, flock or curl was not found, exiting."
1050+
echo "awk, mktemp, flock or curl was not found, exiting."
10421051
exit 1
10431052
fi
10441053

patchman-client.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ License: GPLv3
88
URL: http://patchman.openbytes.ie
99
Source: %{expand:%%(pwd)}
1010
BuildArch: noarch
11-
Requires: curl which coreutils util-linux gawk jq
11+
Requires: curl coreutils util-linux gawk jq
1212

1313
%define _binary_payload w9.gzdio
1414

0 commit comments

Comments
 (0)