-
Notifications
You must be signed in to change notification settings - Fork 0
/
aurget
executable file
·52 lines (44 loc) · 851 Bytes
/
aurget
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
#!/bin/bash
#
# Copyright (c) 2012, Clemens Buchacher <[email protected]>
#
# The code in query() is originally from packer, if I recall correctly.
#
# Depends on curl, jshon.
#
set -e
AURURL='https://aur.archlinux.org'
usage() {
echo "$(basename $0) package" >&2
exit 1
}
query() # name : array
{
field=$1
pkg=$2
j="$(curl -Gs --data-urlencode "arg=$pkg" "$AURURL/rpc.php?type=info")"
if test "$(jshon -e resultcount <<< "$j")" -ne 1
then
echo "Not found: $pkg" >&2
return 2
fi
jshon -e results -e "$field" -u <<< "$j"
}
if test $# -ne 1
then
usage
fi
path=$(query URLPath "$1")
archive=$(mktemp)
curl -Gs "${AURURL}${path}" >"$archive"
tar tzf "$archive" | cut -f1 -d/ | uniq |
while read dir
do
if test -e "$dir"
then
echo "Cannot overwrite existing directory: $dir" >&2
exit 2
fi
done
tar xzf "$archive"
rm -f "$archive"