-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo_pkgs.sh
executable file
·45 lines (36 loc) · 1.05 KB
/
info_pkgs.sh
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
#!/bin/bash
LANG=C
DATA_ITEM="{}"
STATE=0
pacman -Syy
mkdir -p results
function extract_info(){
pkgname=$1
echo "Extracting $pkgname"
mkdir -p $(dirname results/$pkgname.json)
{
while read -r;
do
if [ -z "$REPLY" ]; then
STATE=0
DATA_ITEM="{}"
else
if [[ "$STATE" == 0 ]]; then
STATE=1
fi
K=$(echo $REPLY | cut -d ':' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
V=$(echo $REPLY | cut -d ':' -f2- | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e "s/\"/\'/g")
DATA_ITEM=$(echo $DATA_ITEM | jq ". + {\"$K\":\"$V\"}")
fi
done
}<<<$(pacman -Sii $pkgname)
echo $DATA_ITEM > results/$pkgname.json
}
{
while read -r;
do
extract_info $REPLY &
[ $( jobs | wc -l ) -ge $( nproc ) ] && wait
done
}<<<$(pacman -Sl | cut -f1-2 -d ' ' | sed 's/ /\//')
find results -type f -name "*.json" | xargs -I @ cat @ | jq -s '. | [.[] | {Name,Version,Repository}]' > results/_pkgs_brief.json