blob: fbe7c1bd58adc77f966621856960d6a27b1384b4 (
plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#!/bin/bash
usage() {
>&2 echo 'Verwendung:'
>&2 echo "${ich} [-d|--download URL] [-a|--alle] [-s|--suche wonach] [-i|--intensiv] [-x|--exakt]"
exit 1
}
verpackung() {
typ="$(file -bizL "$1")"
case "${typ}" in
"application/x-tar; charset=binary compressed-encoding=application/x-xz; charset=binary")
echo "-J"
;;
"application/x-tar; charset=binary compressed-encoding=application/x-gzip; charset=binary" | \
"application/octet-stream; charset=binary compressed-encoding=application/x-gzip; charset=binary")
echo "-z"
;;
"ERROR: (null)" | \
"inode/x-empty; charset=binary")
;;
*)
>&2 echo "FEHLER: Unbekannter Verpackungstyp '${typ}'"
;;
esac
}
ich="$(readlink -f "$0")"
pfad="$(dirname "${ich}")/.checkAllRepos"
[ ! -d "${pfad}" ] && mkdir -p "${pfad}"
eval set -- "$(
getopt -o ad:is:x \
--long alle \
--long download: \
--long exakt \
--long intensiv \
--long suche: \
-n "$(basename "$0")" \
-- "$@" \
|| echo "usage"
)"
args=("$@")
unset downloads suchen
alle=false
exakt=false
intensiv=false
while true
do
case "$1" in
-d|--download)
shift
if [ -n "$1" ]
then
downloads[${#downloads[@]}]="$1"
fi
;;
-a|--alle)
alle=true
;;
-x|--exakt)
exakt=true
;;
-i|--intensiv)
intensiv=true
;;
-s|--suche)
shift
if [ -n "$1" ]
then
suchen[${#suchen[@]}]="$1"
fi
;;
--)
shift
break
;;
*)
>&2 echo "FEHLER: Kenne Option '$1' doch nicht"
exit 1
;;
esac
shift
done
if [ $# -ne 0 ]
then
echo 'FEHLER: Zu viele Argumente'
usage
fi
if ${alle}
then
curl "https://wiki.archlinux.org/index.php/Unofficial_user_repositories" 2> /dev/null | \
sed 's|#.*$||' | \
sed '
:begin;
$!N;
s@^\(<pre>.*\)\n\([^<]\+\)$@\1 \2@;
tbegin;
P;
D
' | \
grep "^<pre>" | \
sed "s|^<pre> \[\([^]]*\)].*\sServer = \(\S\+\)\(\s.*\)\?\$|\1 \2/\1.db|" | \
sed "s|^\(\S\+\)\s\+\(.*\)\$repo|\1 \2\1|; s|\$arch|x86_64|" | \
sed "s|^\S\+\s\+||" | \
parallel -j0 "${ich} -d {}"
fi
for ((i=0;i<${#downloads[@]};i++))
do
err=false
ziel="${pfad}/${downloads[${i}]##*/}"
curl -o "${ziel}" "${downloads[${i}]}" 2> /dev/null || err=true
if ! ${err}
then
verp=$(verpackung "${ziel}")
if ! tar ${verp} -tf "${ziel}" &> /dev/null
then
[ -n "${verp}" ] && \
echo tar ${verp} -tf "${ziel}" || \
err=true
fi
fi
if ${err}
then
rm -f "${ziel}"
else
echo "${ziel##*/} erfolgreich heruntergeladen"
fi
done
for ((i=0;i<${#suchen[@]};i++))
do
suchName="${suchen[${i}]}"
${exakt} && suchName="^\(${suchName}\)-[^-]\+-[^-]\+\$"
for db in ${pfad}/*.db
do
if tar $(verpackung "${db}") -tf "${db}" | \
grep "/\$" |
sed "s|/\$||" |
grep -q "${suchName}"
then
echo "'$(basename "${db}" .db)' enthält ein Paket, welches auf '${suchen[${i}]}' passt:"
tar $(verpackung "${db}") -tf "${db}" | \
grep "/\$" |
sed "s|/\$||" |
grep "${suchName}" | \
sed "s|^\(.*\)\$| '\1'|"
fi
if ${intensiv}
then
for pkg in $(tar $(verpackung "${db}") -tf "${db}" --wildcards "*/desc")
do
inhalt="$(
tar $(verpackung "${db}") -Oxf "${db}" "${pkg}" | \
sed '
:begin;
$!N;
s@^\(%[^ %]*%.*\)\n\(.*\S.*\)$@\1 \2@;
tbegin;
P;
D
' | \
grep "^%DESC%" | \
sed "s|^%DESC%\s*||"
)"
if echo "${inhalt}" | \
grep -q "${suchen[${i}]}"
then
echo "Die Beschreibung von Paket '${pkg%/desc}' aus '$(basename "${db}" .db)' passt auf '${suchen[${i}]}':"
echo " ${inhalt}" | \
grep --color=auto "${suchen[${i}]}"
fi
done
fi
done
done
|