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:')
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_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") ;;
46 shift; conf_args
+=(--config "$1") ;;
56 mode
=upgrades
; vercmp_args
+=(-a) ;;
60 parse_args
+=(-q); vercmp_args
+=(-q) ;;
64 shift; mode
=attr
; attr
=$1 ;;
66 shift; parse_args
+=(--search "$1") ;;
68 shift; parse_args
+=(--search-by "$1") ;;
73 --path-list|
--list-path)
75 --repo-list|
--list-repo)
77 --attr-list|
--list-attr)
80 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
81 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
88 # assign environment variables
89 : "${db_ext=$AUR_DBEXT}" "${db_name=$AUR_REPO}" "${db_root=$AUR_DBROOT}"
91 # parse pacman configuration
92 unset conf_file_repo conf_file_serv conf_file_path server
94 while read -r key _ value; do
103 server=${value#file://}
104 conf_file_repo+=("$section")
105 conf_file_serv+=("$server")
106 conf_file_path+=("$server/$section.
${db_ext:-db}")
108 if [[ $section == "$db_name" ]] && [[ ! $db_root ]]; then
112 if [[ $section == "$db_name" ]] && [[ ! $db_root ]]; then
116 done < <(pacman-conf "${conf_args[@]}")
119 # list information on available local repositories
122 if ! (( ${#conf_file_repo[@]} )); then
123 printf >&2 '%s: no file:// repository configured\n' "$argv0"
127 realpath -- "${conf_file_path[@]}" # resolve repo-add symlinks
130 printf '%s\n' "${conf_file_repo[@]}"
133 aur repo-parse --list-attr
137 # select local repository from pacman configuration, if no repository
138 # was specified on the command-line
139 if ! [[ $db_name ]]; then
140 case ${#conf_file_repo[@]} in
141 1) db_name=${conf_file_repo[0]}
142 db_root=${conf_file_serv[0]}
144 0) printf >&2 '%s: no file:// repository configured\n' "$argv0"
147 *) printf >&2 '%s: repository choice is ambiguous (use -d to specify)\n' "$argv0"
149 for i in "${!conf_file_repo[@]}"; do
150 printf '%q\t%q\n' "${conf_file_repo[$i]}" "${conf_file_path[$i]}"
151 done | column -o $'\t' -t >&2
160 if [[ ! $db_root ]]; then
161 printf >&2 '%s: %s: repository root not found\n' "$argv0" "$db_name"
163 elif [[ $db_root == *://* ]]; then
164 printf >&2 '%s: %s: object is remote (use -S to query)\n' "$argv0" "$db_root"
167 db_path=$db_root/$db_name.${db_ext:-db}
168 db_path=$(realpath -- "$db_path") # resolve repo-add symlink
171 db_path=$pacman_dbpath/sync/$db_name.${db_ext:-db}
175 if [[ ! -f $db_path ]]; then
176 printf >&2 '%s: %s: not a file\n' "$argv0" "$db_path"
180 # database operations
182 list|table|json|jsonl)
183 aur repo-parse "${parse_args[@]}" -p "$db_path" --"$mode"
186 aur repo-parse "${parse_args[@]}" -p "$db_path" --jsonl | aur format "${format_args[@]}" -f "$format"
189 aur repo-parse "${parse_args[@]}" -p "$db_path" --list | aur vercmp "${vercmp_args[@]}"
192 aur repo-parse "${parse_args[@]}" -p "$db_path" --attr "$attr"
195 printf '%s\n' "$db_path"
198 printf 'repo:%s\nroot:%s\npath:%s\n' "$db_name" "$db_root" "$db_path"
202 # vim: set et sw=4 sts=4 ft=sh: