-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
aur_json
executable file
·46 lines (35 loc) · 862 Bytes
/
aur_json
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
#!/bin/bash
#
# raw json fetcher for the AUR
#
out() {
type -p json_reformat >/dev/null && json_reformat || cat
}
case $# in
1) qtype=info arg=$1 ;;
2) qtype=$1 arg=$2 ;;
*) exit 1 ;;
esac
[[ $qtype = @(info|?(m)search) ]] || exit 2
# open connection
exec 4<>/dev/tcp/aur.archlinux.org/80
# send http request (avoid 1.1 so we don't have to handle a keep-alive)
printf 'GET /rpc.php?type=%s&arg=%s HTTP/1.0\r
User-Agent: bashium 0.1\r
Host: aur.archlinux.org\r
Accept: */*\r
Accept-Encoding: deflate, gzip\r
\r
' "$qtype" "$arg" >&4
# read http response code
read -r -u 4 _ resp _
if [[ $resp ]] && (( resp >= 300 )); then
echo "error: server responded with HTTP $resp"
exit 1
fi
# read response until the end of the headers
while read -r -u 4 body; do
[[ $body = $'\r' ]] && break
done
# gunzip the remainder of the FD
gzip -d <&4 | out