-
Notifications
You must be signed in to change notification settings - Fork 2
/
yum-packages
executable file
·103 lines (89 loc) · 2.24 KB
/
yum-packages
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
#!/bin/zsh
setopt extendedglob
yum=/var/cache/yum
function die { echo 1>&2 $*; exit 1 }
function release_number {
local release=$1 outVarName=$2
zmodload zsh/regex
[[ $release -regex-match '([[:digit:]]+)' ]] || return 1
integer -g "$outVarName=$MATCH"
}
release_number "$(< /etc/redhat-release)" relno ||
die "Can't find redht release number"
if [[ -d $yum/$CPUTYPE/$relno ]]; then
repodir=$yum/$CPUTYPE/$relno
dbfile=\*primary.'(xml.gz.)#'sqlite
elif [[ -d $yum/fedora ]]; then
repodir=$yum
dbfile=\*primary.sqlite
else
repodir=$yum
dbfile=primary.xml.gz.sqlite
fi
repos=($repodir/^*debuginfo/$~dbfile)
function usage {
cat 1>&2 <<EOF
Usage: ${0:t} [-A] [-s] [-o colName,..] pkgPattern...
Search package directly from yum sqlite db.
Options:
-A AND search for pkgPatterns. (Default is OR)
-s search from summary.
-o colName output column selection. eg. '-o name,version'
-d list databases and exit.
EOF
exit
}
zparseopts -D h=o_help s=opt_s A=opt_AND d=o_listdb \
-AND=opt_AND \
o:=opt_output_fields
if (($#o_help)); then
usage
fi
if (($#o_listdb)); then
(($#repos)) || exit 1
# output as assocarray(typeset -A) suitable format.
for db in $repos; do
# reponame dbfile
print ${${db#$repodir/}/\/*/} $db
done
exit
fi
column=name
if [[ -n $opt_s ]]; then
column=summary
fi
WHERE=''
if ((ARGC)); then
where=()
integer i
local name value
for arg in $argv; do
if [[ $arg == *=* ]]; then
i=$arg[(ri)=]
name=$arg[1,$i-1]
value=$arg[$i+1,-1]
where+=("$name glob ${(qq)value}")
else
where+=("$column glob '$arg'")
fi
done
if (($#opt_AND)); then
WHERE="WHERE ${(j/ AND /)where}"
else
WHERE="WHERE ${(j/ OR /)where}"
fi
fi
nltab=$'\n\t'
for db in $repos; do
# repo=${${db#/var/cache/yum/}%/$dbfile}
repo=${${db#/var/cache/yum/}:h}
if (($#opt_output_fields)); then
sql="select ${(j/,/)opt_output_fields[2,-1]}"
sql+=" from packages $WHERE order by name"
else
sql='select name, version, release, '${(qqq)repo}
sql+=', '${(qqq)nltab}' || summary from packages '$WHERE' order by name'
fi
[[ -n $DEBUG ]] && print -r sql=$sql
sqlite3 -separator $'\t' $db $sql
done