Merge pull request #1030 from AladW/build-conf-fallback
[aurutils.git] / lib / aur-build--pkglist
blobc06c55039770a02657970975342bdf868cd67b78
1 #!/bin/bash
2 [[ -v AUR_DEBUG ]] && set -o xtrace
3 set -o errexit
4 argv0=build--pkglist
5 PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
7 # default options
8 lint=0 mode=pkglist
10 usage() {
11 printf >&2 'usage: %s [--srcinfo] [--lint] [--config <file>]' "$argv0"
12 exit 1
15 source /usr/share/makepkg/util/option.sh
16 source /usr/share/makepkg/util/parseopts.sh
17 source /usr/share/makepkg/util/config.sh
19 # option parsing
20 opt_short='p:U:'
21 opt_long=('buildscript:' 'user:' 'config:' 'lint' 'srcinfo' 'full')
22 opt_hidden=('dump-options')
24 if ! parseopts "$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
25 usage
27 orig_argv=("$@") # original arguments for setpriv(1)
28 set -- "${OPTRET[@]}"
30 unset buildscript build_user makepkg_conf
31 while true; do
32 case "$1" in
33 -p|--buildscript)
34 shift; buildscript=$1 ;;
35 -U|--user)
36 shift; build_user=$1 ;;
37 --config)
38 shift; makepkg_conf=$1 ;;
39 --full)
40 mode=pkglist_full ;;
41 --srcinfo)
42 mode=srcinfo ;;
43 --lint)
44 lint=1 ;;
45 --dump-options)
46 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
47 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
48 exit ;;
49 --) shift; break ;;
50 esac
51 shift
52 done
54 # drop permissions for sourcing PKGBUILDs
55 if (( UID == 0 )) && (( $(id -u "$build_user") != 0 )); then
56 exec setpriv --reuid "$build_user" --regid "$build_user" --init-groups --reset-env \
57 env PKGDEST="$PKGDEST" "${BASH_SOURCE[0]}" "${orig_argv[@]}"
59 elif (( UID == 0 )); then
60 printf >&2 '%s: unprivileged --user required\n' "$argv0"
61 exit 1
64 # shellcheck disable=SC1090
65 source "${buildscript-PKGBUILD}"
66 pkgbase=${pkgbase:-$pkgname}
67 PKGDEST=${PKGDEST:-$PWD}
69 # PKGEXT (packagelist), CARCH (lint)
70 load_makepkg_config "${makepkg_conf-}"
72 if (( lint )); then
73 source /usr/share/makepkg/lint_pkgbuild.sh
74 lint_pkgbuild
77 case $mode in
78 pkglist)
79 source /usr/share/makepkg/util/pkgbuild.sh
80 print_all_package_names
82 pkglist_full)
83 source /usr/share/makepkg/util/pkgbuild.sh
84 print_all_package_names | while IFS= read -r; do
85 printf '%s:%s\n' "$pkgbase" "$REPLY"
86 done ;;
87 srcinfo)
88 source /usr/share/makepkg/srcinfo.sh
89 write_srcinfo_content
91 esac