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 attr
=none status
=0 quiet
=0
14 bsdtar
-tf "$1" |
wc -l
18 bsdtar
-Oxf "$2" '*/desc' |
awk -v attr
="^%$1%$" '
20 while (getline && NF != 0) { print; }
25 bsdtar
-Oxf "$1" '*/desc' |
awk -F% '/^%.+%$/ {print $2}' |
sort -u
29 bsdtar
-Oxf "$3" '*/desc' |
awk -v table
="$1" -v quiet
="$2" '
30 function print_previous(format) {
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 format = "%s\t%s\t%s\t%s\n"
50 format = "%1$s\t%4$s\n"
53 /^%FILENAME%$/ && FNR > 1 {
54 print_previous(format)
55 pkgname = pkgbase = pkgver = "-"
74 /^%(MAKE|CHECK)?DEPENDS%$/ {
75 while (table && getline && $0 != "") {
76 dependencies[i++] = $1
81 print_previous(format)
86 printf >&2 'usage: %s [-d repo] [-r path] [-alqtuS]\n' "$argv0"
90 source /usr
/share
/makepkg
/util
/parseopts.sh
93 opt_short
='c:d:r:F:alqtuS'
94 opt_long
=('config:' 'database:' 'root:' 'all' 'list' 'path' 'list-path' 'list-repo'
95 'list-attr' 'sync' 'upgrades' 'table' 'quiet' 'status-file:' 'attr:')
96 opt_hidden
=('dump-options' 'repo:' 'repo-list' 'path-list' 'status')
98 if ! parseopts
"$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
101 set -- "${OPTRET[@]}"
103 unset mode list db_name db_root status_file pacman_conf vercmp_args attr
106 -d|
--database|
--repo)
111 shift; pacman_conf
=$1 ;;
113 mode
=packages
; table_format
=0 ;;
115 mode
=packages
; table_format
=1 ;;
117 mode
=upgrades
; vercmp_args
+=(-a) ;;
123 quiet
=1; vercmp_args
+=(-q) ;;
125 shift; status_file
=$1 ;;
129 shift; mode
=attr
; attr
=$1 ;;
130 ## deprecated options
133 --path-list|
--list-path)
135 --repo-list|
--list-repo)
140 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
141 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
148 if [[ -v pacman_conf ]]; then
149 conf_args+=(--config "$pacman_conf")
152 # assign environment variables
153 : "${db_ext=$AUR_DBEXT}" "${db_name=$AUR_REPO}" "${db_root=$AUR_DBROOT}"
155 unset conf_file_repo conf_file_serv conf_file_path server
156 while read -r key _ value; do
165 server=${value#file://}
166 conf_file_repo+=("$section")
167 conf_file_serv+=("$server")
168 conf_file_path+=("$server/$section.
${db_ext:-db}")
170 if [[ $section == "$db_name" ]]; then
171 if ! [[ $db_root ]]; then
173 elif [[ $db_root != "$server" ]]; then
174 printf >&2 '%s: warning: --root and pacman.conf mismatch (%s)\n' "$argv0" "$db_name"
179 if [[ $section == "$db_name" ]] && ! [[ $db_root ]]; then
184 done < <(pacman-conf "${conf_args[@]}")
187 # list information on available local repositories
190 if ! [[ ${conf_file_repo[*]} ]]; then
191 printf >&2 '%s: no file:// repository configured\n' "$argv0"
196 realpath -- "${conf_file_path[@]}" # resolve repo-add symlink
200 printf '%s\n' "${conf_file_repo[@]}"
205 # select local repository from pacman configuration, if no repository
206 # was specified on the command-line
207 if ! [[ $db_name ]]; then
208 case ${#conf_file_repo[@]} in
209 1) db_name=${conf_file_repo[0]}
210 db_root=${conf_file_serv[0]}
212 0) printf >&2 '%s: no file:// repository configured\n' "$argv0"
215 *) printf >&2 '%s: repository choice is ambiguous (use -d to specify)\n' "$argv0"
216 for i in "${!conf_file_repo[@]}"; do
217 printf '%q\t%q\n' "${conf_file_repo[$i]}" "${conf_file_path[$i]}"
218 done | column -o $'\t' -t >&2
226 if ! [[ $db_root ]]; then
227 printf >&2 '%s: %s: repository path not found\n' "$argv0" "$db_name"
229 elif [[ $db_root == *://* ]]; then
230 printf >&2 '%s: %s: object is remote (use -S to query)\n' "$argv0" "$db_root"
232 elif ! [[ -d $db_root ]]; then
233 printf >&2 '%s: %s: not a directory\n' "$argv0" "$db_root"
236 db_path=$db_root/$db_name.${db_ext:-db}
237 db_path=$(realpath -- "$db_path") # resolve repo-add symlink
240 db_path=$pacman_dbpath/sync/$db_name.${db_ext:-db}
244 if [[ ! -f $db_path ]]; then
245 printf >&2 '%s: %s: not a file\n' "$argv0" "$db_path"
247 elif (( status )); then
248 printf 'repo:%s\nroot:%s\npath:%s\n' "$db_name" "$db_root" "$db_path"
249 elif [[ -v status_file ]]; then
250 printf 'repo:%s\nroot:%s\npath:%s\n' "$db_name" "$db_root" "$db_path" >"$status_file"
253 # empty mode, only print path
254 if [[ $mode == "path
" ]]; then
255 printf '%s\n' "$db_path"
259 # do not extract an empty database (#727)
260 if ! (( $(db_count "$db_path") )); then
264 # database operations
267 db_table "0" "0" "$db_path" | aur vercmp "${vercmp_args[@]}"
270 db_table "$table_format" "$quiet" "$db_path"
273 db_attr "${attr^^}" "$db_path"
276 db_attr_list "$db_path"
282 # vim: set et sw=4 sts=4 ft=sh: