-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathawx-csv-host-versions2table
executable file
·105 lines (78 loc) · 2.57 KB
/
awx-csv-host-versions2table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# This script comes with ABSOLUTELY NO WARRANTY, use at own risk
# Copyright (C) 2021 Osiris Alejandro Gomez <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# shellcheck disable=SC1090
# shellcheck disable=SC1091
# shellcheck source=/dev/null
DIR_BIN=$(dirname "$0") && source "$DIR_BIN/awx-common"
function usage()
{
cat << EOF
Usage:
\`\`\`bash
$BIN CSV
\`\`\`
Convert \`.csv\` with host versions to table group by version.
Example:
$BIN awx-host-versions.csv
vers v1.0.0 v1.1.0 v1.1.1 v1.1.2 v1.1.3
n01 0 0 19 0 1
n02 0 0 8 0 0
n03 0 0 13 0 0
n04 0 0 15 0 0
n05 2 0 9 0 0
n06 2 0 5 0 0
n07 2 0 5 0 0
n08 1 0 5 0 0
n00 2 0 4 0 0
n09 1 0 6 0 0
n10 4 1 1 2 0
EOF
exit 0
}
[[ "$1" =~ ^[-]+(h|help) ]] && usage
TMP1="$(mktemp)"
TMP2="$(mktemp)"
REGEX='v[0-9]+\.[0-9]+\.[0-9]+'
CSV='awx-host-versions.csv'
[[ -z "$1" ]] && CSV="$1"
CSV="$1"
[[ ! -e "$CSV" ]] && die "NOT FOUND CSV $CSV"
[[ ! -s "$CSV" ]] && die "EMPTY $CSV"
# get unique versions
awk '{print $4}' "$CSV" | grep -Eo "$REGEX" | sort -u > "$TMP1"
# get unique networks
awk '{print $1}' "$CSV" | sort -u > "$TMP2"
# print colunm headers
printf "%-10s " "vers "
while read -r VERSION
do
printf "%9s " "$VERSION"
done < "$TMP1"
printf "\\n"
# print rows
while read -r NETWORK
do
printf "%-10s " "$NETWORK"
# print columns
while read -r VERSION
do
TOTAL="$(grep -Ec "$NETWORK.*$VERSION" "$CSV")"
printf "%9d " "$TOTAL"
done < "$TMP1"
printf "\\n"
done < "$TMP2"
rm -f "$TMP1" "$TMP2"