2 # aur-srcver - update and print package revisions
3 [[ -v AUR_DEBUG
]] && set -o xtrace
6 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
9 # XXX: --skipinteg is an optional argument
10 makepkg_args
=('--nobuild' '--nodeps' '--skipinteg')
11 num_procs
=$
(( "$(nproc)" + 2 ))
14 # shellcheck disable=SC2155
15 local str
=$
(printf '%s,' "$@")
16 printf '%s' "${str%,}"
19 # shellcheck disable=SC2154
21 if (( epoch
> 0 )); then
22 printf "%s\n" "$epoch:$pkgver-$pkgrel"
24 printf "%s\n" "$pkgver-$pkgrel"
29 if [[ ! -v AUR_DEBUG
]]; then
32 printf >&2 'AUR_DEBUG: %s: temporary files at %s\n' "$argv0" "$tmp"
37 printf >&2 'usage: %s [--no-prepare] <pkgbase> [<pkgbase> ...]\n' "$argv0"
41 # mollyguard for makepkg
42 if (( UID
== 0 )) && [[ ! -v AUR_ASROOT
]]; then
43 printf >&2 'warning: aur-%s is not meant to be run as root.\n' "$argv0"
44 printf >&2 'warning: To proceed anyway, set the %s variable.\n' 'AUR_ASROOT'
50 opt_long
=('arg-file:' 'no-prepare' 'jobs:' 'buildscript:' 'margs:' 'makepkg-args:' 'null')
51 opt_hidden
=('dump-options' 'noprepare')
53 if opts
=$
(getopt
-o "$opt_short" -l "$(args_csv "${opt_long[@]}" "${opt_hidden[@]}")" -n "$argv0" -- "$@"); then
59 unset arg_file buildscript mapfile_args
64 --noprepare|
--no-prepare)
65 makepkg_args
+=(--noprepare) ;;
66 --makepkg-args|
--margs)
67 shift; IFS
=, read -a arg
-r <<< "$1"
68 makepkg_args
+=("${arg[@]}") ;;
70 shift; num_procs
=$1 ;;
73 makepkg_args
+=(-p "$1") ;;
75 mapfile_args
+=(-d $
'\0') ;;
77 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
78 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
86 # Single hyphen to denote input taken from stdin
88 if (( $# == 1 )) && [[ $1 == "-" || $1 == "/dev
/stdin
" ]]; then
92 # shellcheck disable=SC2174
93 mkdir -pm 0700 -- "${TMPDIR:-/tmp}/aurutils-
$UID"
94 tmp=$(mktemp -d --tmpdir "aurutils-
$UID/$argv0.XXXXXXXX
") || exit
97 # A pipeline `foo | bar &` causes `bar` to detach from the script. In
98 # this case, aur-srcver returns immediately with `makepkg` processes
99 # still running in the background. Read all input into an array to
100 # avoid this. (cf. aur-view, #958)
102 mapfile "${mapfile_args[@]}" -t packages
104 elif [[ -v argfile ]]; then
105 mapfile "${mapfile_args[@]}" -t packages <"$arg_file"
107 packages=("${@:-$PWD}")
111 # Remove duplicates in pkgbuild dirs
114 i=0 # package counter
115 for n in "${packages[@]}"; do
116 n=$(realpath "$n"); [[ ${seen[$n]} ]] && continue
119 if (( i++ >= num_procs )); then
123 { mkdir -p -- "$tmp/$i"
124 echo "$n" > "$tmp/$i"/path
127 #shellcheck disable=SC2086
128 env -C "$n" nice -n 20 ${AUR_MAKEPKG:-makepkg} \
129 "${makepkg_args[@]}" >"$tmp/$i"/log 2>&1 || mpkg_err=$?
131 if (( mpkg_err )); then
132 echo "$mpkg_err" >"$tmp/$i"/failed
139 for d in "$tmp"/*/; do # iterate over directories
140 i=$(basename "$d") p=$(<"$d"/path)
142 if [[ -e $d/failed ]]; then
145 # Precautions when sourcing the PKGBUILD have no effect here,
146 # because makepkg already sourced the PKGBUILD above.
147 # shellcheck disable=SC1090
148 ( source "$p/${buildscript-PKGBUILD}"
150 fullver=$(get_full_version)
151 printf '%s\t%s\n' "${pkgbase:-$pkgname}" "$fullver"
156 for i in "${!failed[@]}"; do
157 printf >&2 '%s: makepkg %s failed for path %s with exit %s\n' \
158 "$argv0" "${makepkg_args[*]}" "${failed[$i]}" "$
(<"$tmp/$i"/failed
)"
160 cat "$tmp/$i"/log >&2
161 printf >&2 '8<----\n'
164 if (( ${#failed[@]} )); then
168 # vim: set et sw=4 sts=4 ft=sh: