2 # aur-repo - operate on local repositories
3 [[ -v AUR_DEBUG
]] && set -o xtrace
5 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
8 db_query
=file mode
=none conf_args
=() vercmp_args
=() parse_args
=()
11 # shellcheck disable=SC2155
12 local str
=$
(printf '%s,' "$@")
13 printf '%s' "${str%,}"
17 printf >&2 'usage: %s [-d repo] [-r path] [-alqtuS]\n' "$argv0"
22 opt_short
='c:f:d:r:s:F:alqtuJS'
23 opt_long
=('config:' 'database:' 'root:' 'all' 'list' 'path' 'list-path' 'list-repo'
24 'search:' 'search-by:' 'list-attr' 'sync' 'upgrades' 'table' 'quiet'
25 'attr:' 'json' 'jsonl' 'format:' 'delim:' 'dbext:')
26 opt_hidden
=('dump-options' 'repo:' 'repo-list' 'path-list' 'attr-list' 'status' 'field:')
28 if opts
=$
(getopt
-o "$opt_short" -l "$(args_csv "${opt_long[@]}" "${opt_hidden[@]}")" -n "$argv0" -- "$@"); then
34 unset mode list db_ext db_name db_root format status_file pacman_conf format_args vercmp_args attr
40 shift; format
=$1; mode
=format
;;
42 shift; format_args
+=(--delim "$1") ;;
48 shift; pacman_conf
=$1; conf_args
+=(--config "$1") ;;
58 mode
=upgrades
; vercmp_args
+=(-a) ;;
62 parse_args
+=(-q); vercmp_args
+=(-q) ;;
66 shift; mode
=attr
; attr
=$1 ;;
68 shift; parse_args
+=(--search "$1") ;;
70 shift; parse_args
+=(--search-by "$1") ;;
75 --path-list|
--list-path)
77 --repo-list|
--list-repo)
79 --attr-list|
--list-attr)
82 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
83 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
90 # assign environment variables
91 db_ext=${db_ext:-$AUR_DBEXT} db_name=${db_name:-$AUR_REPO} db_root=${db_root:-$AUR_DBROOT}
94 if [[ $db_query == 'sync' ]] && [[ $db_root ]]; then
95 printf >&2 'warning: ignoring repository root %q with --sync\n' "$db_root"
98 # parse pacman configuration
99 declare -A conf_file_serv conf_file_path conf_sync_serv
101 while read -r key _ value; do
107 pacman_dbpath=${value%/}
110 value=${value#file://}
112 conf_file_serv[$section]=$value
113 conf_file_path[$section]=$value/$section.${db_ext:-db}
116 conf_sync_serv[$section]=$value
118 if [[ $section == "$db_name" ]] && [[ ! $db_root ]]; then
122 done < <(pacman-conf "${conf_args[@]}")
125 # list information on available local repositories
128 if ! [[ ${!conf_file_path[*]} ]]; then
129 printf >&2 '%s: no file:// repository configured\n' "$argv0"
133 # XXX: file paths not quoted
134 realpath -- "${conf_file_path[@]}" # resolve repo-add symlinks
137 printf '%q\n' "${!conf_file_path[@]}"
140 aur repo-parse --list-attr # holds for any repository
144 # select local repository from pacman configuration, if no repository
145 # was specified on the command-line
146 if [[ ! $db_name ]]; then
147 conf_file_repo=("${!conf_file_serv[@]}")
149 case ${#conf_file_repo[@]} in
150 1) db_root=${conf_file_serv[${conf_file_repo[0]}]}
151 db_name=${conf_file_repo[0]}
153 0) printf >&2 '%s: no file:// repository configured\n' "$argv0"
156 *) printf >&2 '%s: repository choice is ambiguous (use -d to specify)\n' "$argv0"
158 for db in "${conf_file_repo[@]}"; do
159 printf '%q\t%q\n' "$db" "${conf_file_path[$db]}"
160 done | column -o $'\t' -t >&2
165 # check $db_name is a configured pacman repository (local or remote, #1113)
166 elif ! [[ ${conf_sync_serv[$db_name]} ]]; then
167 # disambiguate used pacman.conf (#1118)
168 if [[ -v pacman_conf ]]; then
169 printf >&2 "%s
: %q
: repository
%q not configured
\n" "$argv0" "$pacman_conf" "$db_name"
171 printf >&2 "%s
: repository
%q not configured
\n" "$argv0" "$db_name"
179 if [[ ! $db_root ]]; then
180 printf >&2 '%s: %q: repository root not found\n' "$argv0" "$db_name"
182 elif [[ $db_root == *://* ]]; then
183 printf >&2 '%s: %q: object is remote (use -S to query)\n' "$argv0" "$db_root"
186 db_path=$db_root/$db_name.${db_ext:-db}
189 db_path=$pacman_dbpath/sync/$db_name.${db_ext:-db}
190 db_root=$pacman_dbpath/sync
194 # check file attributes
195 if [[ ! -d $db_root ]]; then
196 printf >&2 '%s: %q: no such directory\n' "$argv0" "$db_root"
198 elif [[ ! -f $db_path ]]; then
199 printf >&2 '%s: %q: no such file\n' "$argv0" "$db_path"
203 # resolve repo-add symlink
204 db_path=$(realpath -- "$db_path")
205 db_root=$(realpath -- "$db_root")
207 # database operations
209 list|table|json|jsonl)
210 aur repo-parse "${parse_args[@]}" -p "$db_path" --"$mode"
213 aur repo-parse "${parse_args[@]}" -p "$db_path" --jsonl | aur format "${format_args[@]}" -f "$format"
216 aur repo-parse "${parse_args[@]}" -p "$db_path" --list | aur vercmp "${vercmp_args[@]}"
219 aur repo-parse "${parse_args[@]}" -p "$db_path" --attr "$attr"
222 printf '%q\n' "$db_path"
225 printf 'repo:%q\nroot:%q\npath:%q\n' "$db_name" "$db_root" "$db_path"
229 # vim: set et sw=4 sts=4 ft=sh: