2 # aur-pkglist - print the AUR package list
3 [[ -v AUR_DEBUG
]] && set -o xtrace
5 XDG_CACHE_HOME
=${XDG_CACHE_HOME:-$HOME/.cache}
6 AUR_LOCATION
=${AUR_LOCATION:-'https://aur.archlinux.org'}
7 AUR_METADEST
=${AUR_METADEST:-$XDG_CACHE_HOME/aurutils/$argv0} # variable name prone to change
8 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
11 ttl
=300 pkglist
=packages update
=0 verify
=0 use_system_time
=0
13 http_last_modified
() {
14 awk -F', ' '/^[Ll]ast-[Mm]odified:/ {print $2}' "$1"
18 curl
-A aurutils
-f "$1" "${@:2}" --remote-name
22 curl
-A aurutils
-f "$1" --head -Ss
26 printf >&2 'usage: %s [-bqsiv] [-t ttl] [-FP pattern]\n' "$argv0"
30 source /usr
/share
/makepkg
/util
/parseopts.sh
32 opt_short
='t:bqsivFPJISu'
33 opt_long
=('pkgbase' 'search' 'info' 'fixed-strings' 'perl-regexp' 'plain'
34 'ttl:' 'users' 'verify' 'quiet' 'systime')
35 opt_hidden
=('dump-options' 'time:' 'json')
37 if ! parseopts
"$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
48 pkglist
=packages-meta-v1.json
;;
50 pkglist
=packages-meta-ext-v1.json
;;
68 -u) printf >&2 'deprecation notice: %s -u is an alias for --quiet\n' "$argv0"
70 -I) printf >&2 'deprecation notice: %s -I is an alias for --info\n' "$argv0"
71 pkglist
=packages-meta-ext-v1.json
;;
72 -S) printf >&2 'deprecation notice: %s -S is an alias for --search\n' "$argv0"
73 pkglist
=packages-meta-v1.json
;;
75 printf >&2 'deprecation notice: %s --json is an alias for [--info|--search] | jq\n' "$argv0"
78 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
79 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
86 # default to regex if >0 arguments specified
87 if [[ ! -v mode ]] && (( $# > 0 )); then
89 elif [[ ! -v mode ]]; then
93 if ! [[ $ttl =~ [0-9]+ ]]; then
94 printf >&2 "error
: --ttl requires an integer
('%s' provided
)\n" "$ttl"
99 install -dm700 "$AUR_METADEST"
100 cd "$AUR_METADEST" || exit
102 if [[ ! -s headers_$pkglist || ! -s $pkglist ]]; then
105 elif [[ -s $pkglist ]]; then
106 sec_l=$(http_last_modified "headers_
$pkglist" | date -f - '+%s')
108 if (( use_system_time )); then
111 sec_d=$(http_last_modified <(list_headers "$AUR_LOCATION/$pkglist.gz
") | date -f - '+%s')
114 if (( sec_d - sec_l > ttl )); then
119 if (( update )); then
120 list_fetch "$AUR_LOCATION/$pkglist.gz
" --dump-header "headers_
$pkglist"
122 if (( verify )); then
123 list_fetch "$AUR_LOCATION/$pkglist.gz.sha256
"
124 sha256sum --check --strict --quiet "$pkglist.gz.sha256
" || exit
127 if [[ $pkglist == *.json ]]; then
128 # Remove newlines separating partial objects, i.e.
129 # [\n{...},\n{...},...\n] => [{...}{...},...]\n
130 { gunzip -c "$pkglist.gz
" | tr -d '\n'
134 gunzip -f "$pkglist.gz
"
143 grep -F "$1" "$pkglist" ;;
145 grep -P "$1" "$pkglist" ;;
147 printf '%s\n' "$PWD/$pkglist" ;;
150 # vim: set et sw=4 sts=4 ft=sh: