2 # aur-repo - manage local repositories
3 [[ -v AUR_DEBUG
]] && set -o xtrace
5 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
8 db_query
=local table_format
=0 mode
=none field
=none status
=0
14 # do not extract an empty database (#727)
15 (( $
(bsdtar
-tf "$2" |
wc -l) )) ||
return 0
17 bsdtar
-Oxf "$2" '*/desc' |
awk -v field
="^%$1%$" '
19 while (getline && NF != 0) { print; }
24 # do not extract an empty database (#727)
25 (( $
(bsdtar
-tf "$2" |
wc -l) )) ||
return 0
27 bsdtar
-Oxf "$2" '*/desc' |
awk -v table
="$1" '
28 function print_previous() {
29 table ? format = "%s\t%s\t%s\t%s\n" : format = "%1$s\t%4$s\n"
31 ## Add dependency to self (packages with no dependencies)
32 printf format, pkgname, pkgname, pkgbase, pkgver
35 for (i in dependencies) {
36 printf format, pkgname, dependencies[i], pkgbase, pkgver
42 pkgname = pkgbase = pkgver = "-"
43 delete dependencies[0]
46 /^%FILENAME%$/ && FNR > 1 {
48 pkgname = pkgbase = pkgver = "-"
67 /^%(MAKE|CHECK)?DEPENDS%$/ {
68 while (table && getline && $0 != "") {
69 dependencies[i++] = $1
79 printf >&2 'usage: %s [-d repo] [-r path] [-alqtuS]\n' "$argv0"
83 source /usr
/share
/makepkg
/util
/parseopts.sh
86 opt_short
='c:d:r:F:alqtuS'
87 opt_long
=('config:' 'database:' 'repo:' 'root:' 'all' 'list' 'path'
88 'path-list' 'repo-list' 'sync' 'upgrades' 'table' 'quiet'
89 'status-file:' 'field:')
90 opt_hidden
=('dump-options' 'list-repo' 'list-path' 'status')
92 if ! parseopts
"$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
97 unset mode list db_name db_root status_file pacman_conf vercmp_args field
100 -d|
--database|
--repo)
105 shift; pacman_conf
=$1 ;;
107 mode
=packages
; table_format
=0 ;;
109 mode
=packages
; table_format
=1 ;;
111 mode
=upgrades
; vercmp_args
+=(-a) ;;
113 mode
=upgrades
; vercmp_args
+=(-q) ;;
117 shift; status_file
=$1 ;;
121 shift; mode
=files
; field
=$1 ;;
122 ## deprecated options
125 --path-list|
--list-path)
127 --repo-list|
--list-repo)
132 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
133 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
140 if [[ -v pacman_conf ]]; then
141 conf_args+=(--config "$pacman_conf")
144 # assign environment variables
145 : "${db_ext=$AUR_DBEXT}" "${db_name=$AUR_REPO}" "${db_root=$AUR_DBROOT}"
147 unset conf_file_repo conf_file_serv conf_file_path server
148 while read -r key _ value; do
157 server=${value#file://}
158 conf_file_repo+=("$section")
159 conf_file_serv+=("$server")
160 conf_file_path+=("$server/$section.
${db_ext:-db}")
162 if [[ $section == "$db_name" ]]; then
163 if ! [[ $db_root ]]; then
165 elif [[ $db_root != "$server" ]]; then
166 printf >&2 '%s: warning: --root and pacman.conf mismatch (%s)\n' "$argv0" "$db_name"
171 if [[ $section == "$db_name" ]] && ! [[ $db_root ]]; then
176 done < <(pacman-conf "${conf_args[@]}")
179 # list information on available local repositories
182 if ! [[ ${conf_file_repo[*]} ]]; then
183 printf >&2 '%s: no file:// repository configured\n' "$argv0"
188 realpath -- "${conf_file_path[@]}" # resolve repo-add symlink
192 printf '%s\n' "${conf_file_repo[@]}"
197 # select local repository from pacman configuration, if no repository
198 # was specified on the command-line
199 if ! [[ $db_name ]]; then
200 case ${#conf_file_repo[@]} in
201 1) db_name=${conf_file_repo[0]}
202 db_root=${conf_file_serv[0]}
204 0) printf >&2 '%s: no file:// repository configured\n' "$argv0"
207 *) printf >&2 '%s: repository choice is ambiguous (use -d to specify)\n' "$argv0"
208 for i in "${!conf_file_repo[@]}"; do
209 printf '%q\t%q\n' "${conf_file_repo[$i]}" "${conf_file_path[$i]}"
210 done | column -o $'\t' -t >&2
218 if ! [[ $db_root ]]; then
219 printf >&2 '%s: %s: repository path not found\n' "$argv0" "$db_name"
221 elif [[ $db_root == *://* ]]; then
222 printf >&2 '%s: %s: object is remote (use -S to query)\n' "$argv0" "$db_root"
224 elif ! [[ -d $db_root ]]; then
225 printf >&2 '%s: %s: not a directory\n' "$argv0" "$db_root"
228 db_path=$db_root/$db_name.${db_ext:-db}
229 db_path=$(realpath -- "$db_path") # resolve repo-add symlink
232 db_path=$pacman_dbpath/sync/$db_name.${db_ext:-db}
236 if [[ ! -f $db_path ]]; then
237 printf >&2 '%s: %s: not a file\n' "$argv0" "$db_path"
241 if (( status )); then
242 printf 'repo:%s\nroot:%s\npath:%s\n' "$db_name" "$db_root" "$db_path"
244 elif [[ -v status_file ]]; then
245 printf 'repo:%s\nroot:%s\npath:%s\n' "$db_name" "$db_root" "$db_path" >"$status_file"
250 db_field "${field^^}" "$db_path"
253 db_table '0' "$db_path" | aur vercmp "${vercmp_args[@]}"
256 db_table "$table_format" "$db_path"
259 printf '%s\n' "$db_path"
265 # vim: set et sw=4 sts=4 ft=sh: