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
=() missing
=0
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:i:r:s:F:almqtuJS'
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:' 'missing' 'ignore:' 'ignore-by:')
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") ;;
60 mode
=upgrades
; vercmp_args
+=(-a) ;;
64 parse_args
+=(-q); vercmp_args
+=(-q) ;;
68 shift; mode
=attr
; attr
=$1 ;;
70 shift; parse_args
+=(--search "$1") ;;
72 shift; parse_args
+=(--search-by "$1") ;;
74 shift; parse_args
+=(--ignore "$1") ;;
76 shift; parse_args
+=(--ignore-by "$1") ;;
81 --path-list|
--list-path)
83 --repo-list|
--list-repo)
85 --attr-list|
--list-attr)
88 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
89 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
96 # assign environment variables
97 db_ext=${db_ext:-$AUR_DBEXT} db_name=${db_name:-$AUR_REPO} db_root=${db_root:-$AUR_DBROOT}
100 if [[ $db_query == 'sync' ]] && [[ $db_root ]]; then
101 printf >&2 'warning: ignoring repository root %q with --sync\n' "$db_root"
104 # parse pacman configuration
105 declare -A conf_file_serv conf_file_path conf_sync_serv
107 while read -r key _ value; do
113 pacman_dbpath=${value%/}
116 value=${value#file://}
118 conf_file_serv[$section]=$value
119 conf_file_path[$section]=$value/$section.${db_ext:-db}
122 conf_sync_serv[$section]=$value
124 if [[ $section == "$db_name" ]] && [[ ! $db_root ]]; then
128 done < <(pacman-conf "${conf_args[@]}")
131 # prefix error messages with pacman.conf (#1118)
132 if [[ -v pacman_conf ]]; then
133 err_prefix="$argv0: $pacman_conf"
138 # existing path is optional for printf modes (#1142)
139 if (( missing )); then
142 # require all path components to exist
146 # list information on available local repositories
149 if ! [[ ${!conf_file_path[*]} ]]; then
150 printf >&2 '%s: no file:// repository configured\n' "$err_prefix"
154 # resolve repo-add symlinks
155 realpath "${realpath_args[@]}" -- "${conf_file_path[@]}" || exit 2
158 # quote repository name
159 printf '%s\n' "${!conf_file_path[@]}"
162 aur repo-parse --list-attr # holds for any repository
166 # select local repository from pacman configuration, if no repository
167 # was specified on the command-line
168 if [[ ! $db_name ]]; then
169 conf_file_repo=("${!conf_file_serv[@]}")
171 case ${#conf_file_repo[@]} in
172 1) db_root=${conf_file_serv[${conf_file_repo[0]}]}
173 db_name=${conf_file_repo[0]}
175 0) printf >&2 '%s: no file:// repository configured\n' "$err_prefix"
178 *) printf >&2 '%s: repository choice is ambiguous (use -d to specify)\n' "$err_prefix"
180 for db in "${conf_file_repo[@]}"; do
181 printf '%q\t%q\n' "$db" "${conf_file_path[$db]}"
182 done | column -o $'\t' -t >&2
187 # check $db_name is a configured pacman repository (local or remote, #1113)
188 elif ! [[ ${conf_sync_serv[$db_name]} ]]; then
189 printf >&2 "%s
: repository
%q not configured
\n" "$err_prefix" "$db_name"
196 if [[ $db_root == *://* ]]; then
197 printf >&2 '%s: %q: object is remote (use -S to query)\n' "$argv0" "$db_root"
200 db_path=$db_root/$db_name.${db_ext:-db}
203 db_path=$pacman_dbpath/sync/$db_name.${db_ext:-db}
204 db_root=$pacman_dbpath/sync
208 # resolve repo-add symlink
209 db_path=$(realpath "${realpath_args[@]}" -- "$db_path") || exit 2
210 db_root=$(realpath "${realpath_args[@]}" -- "$db_root") || exit 2
212 # database operations
214 list|table|json|jsonl)
215 aur repo-parse "${parse_args[@]}" -p "$db_path" --"$mode"
218 aur repo-parse "${parse_args[@]}" -p "$db_path" --jsonl | aur format "${format_args[@]}" -f "$format"
221 aur repo-parse "${parse_args[@]}" -p "$db_path" --list | aur vercmp "${vercmp_args[@]}"
224 aur repo-parse "${parse_args[@]}" -p "$db_path" --attr "$attr"
227 printf '%s\n' "$db_path"
230 printf 'repo:%s\nroot:%s\npath:%s\n' "$db_name" "$db_root" "$db_path"
234 # vim: set et sw=4 sts=4 ft=sh: