Skip to content

Commit

Permalink
apt.sh: handle multiple origins in apt-get output (#757)
Browse files Browse the repository at this point in the history
It might happen that a given upgrade comes from multiple origins, in
which case the origins are separated by ", " and thus breaking
whitespace-based split. For example:

Inst package [1.2.3] (1.2.4 Debian:8.10/oldstable, Debian-Security:8/oldstable [amd64])

To workaround this case, mangle the apt-get output to remove whitespaces from
the origins list.
  • Loading branch information
filippog authored and SuperQ committed Dec 12, 2017
1 parent 1e9bb4e commit af4cf20
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion text_collector_examples/apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# Author: Ben Kochie <[email protected]>

upgrades="$(/usr/bin/apt-get --just-print upgrade \
| /usr/bin/awk '/^Inst/ {print $5, $6}' \
| /usr/bin/awk -F'[()]' \
'/^Inst/ { sub("^[^ ]+ ", "", $2); sub("\\[", " ", $2);
sub(" ", "", $2); sub("\\]", "", $2); print $2 }'
| /usr/bin/sort \
| /usr/bin/uniq -c \
| awk '{ gsub(/\\\\/, "\\\\", $2); gsub(/\"/, "\\\"", $2);
Expand Down

0 comments on commit af4cf20

Please sign in to comment.