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}
8 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
11 ttl
=300 pkglist
=packages update
=0 verify
=0 use_system_time
=0
14 # shellcheck disable=SC2155
15 local str
=$
(printf '%s,' "$@")
16 printf '%s' "${str%,}"
19 http_last_modified
() {
20 awk -F', ' '/^[Ll]ast-[Mm]odified:/ {print $2}' "$1"
24 curl
-A aurutils
-f "$1" "${@:2}" --remote-name
28 curl
-A aurutils
-f "$1" --head -Ss
32 printf >&2 'usage: %s [-bqsiv] [-t ttl] [-FP pattern]\n' "$argv0"
36 opt_short
='t:bqsivFPu'
37 opt_long
=('pkgbase' 'search' 'info' 'fixed-strings' 'perl-regexp' 'plain'
38 'ttl:' 'users' 'verify' 'quiet' 'systime')
39 opt_hidden
=('dump-options' 'time:')
41 if opts
=$
(getopt
-o "$opt_short" -l "$(args_csv "${opt_long[@]}" "${opt_hidden[@]}")" -n "$argv0" -- "$@"); then
53 pkglist
=packages-meta-v1.json
;;
55 pkglist
=packages-meta-ext-v1.json
;;
73 -u) printf >&2 'deprecation notice: %s -u is an alias for --quiet\n' "$argv0"
76 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
77 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
84 # default to regex if >0 arguments specified
85 if [[ ! -v mode ]] && (( $# > 0 )); then
87 elif [[ ! -v mode ]]; then
91 if ! [[ $ttl =~ [0-9]+ ]]; then
92 printf >&2 "%s
: --ttl requires an integer
('%s' provided
)\n" "$argv0" "$ttl"
97 mkdir -p -- "$AUR_METADEST"
99 if [[ ! -s $AUR_METADEST/headers_$pkglist || ! -s $AUR_METADEST/$pkglist ]]; then
102 elif [[ -s $AUR_METADEST/$pkglist ]]; then
103 sec_l=$(http_last_modified "$AUR_METADEST/headers_
$pkglist" | date -f - '+%s')
105 if (( use_system_time )); then
108 sec_d=$(http_last_modified <(list_headers "$AUR_LOCATION/$pkglist.gz
") | date -f - '+%s')
111 if (( sec_d - sec_l > ttl )); then
116 if (( update )); then
117 list_fetch "$AUR_LOCATION/$pkglist.gz
" --dump-header "$AUR_METADEST/headers_
$pkglist" -o "$AUR_METADEST/$pkglist.gz
"
119 if (( verify )); then
120 list_fetch "$AUR_LOCATION/$pkglist.gz.sha256
" -o "$AUR_METADEST/$pkglist.gz.sha256
"
121 sha256sum --check --strict --quiet "$AUR_METADEST/$pkglist.gz.sha256
" || exit
124 if [[ $pkglist == *.json ]]; then
125 # Remove newlines separating partial objects, i.e.
126 # [\n{...},\n{...},...\n] => [{...}{...},...]\n
127 { gunzip -c "$AUR_METADEST/$pkglist.gz
" | tr -d '\n'
129 } > "$AUR_METADEST/$pkglist"
131 gunzip -f "$AUR_METADEST/$pkglist.gz
"
138 cat "$AUR_METADEST/$pkglist" ;;
140 grep -F "$1" "$AUR_METADEST/$pkglist" ;;
142 grep -P "$1" "$AUR_METADEST/$pkglist" ;;
144 printf '%s\n' "$AUR_METADEST/$pkglist" ;;
147 # vim: set et sw=4 sts=4 ft=sh: