Merge pull request #1108 from AladW/build-chroot-defaults
[aurutils.git] / lib / aur-build--pkglist
bloba203705d0ac842b9df0fe202d01df18c0d5ea3dc
1 #!/bin/bash
2 [[ -v AUR_DEBUG ]] && set -o xtrace
3 argv0=build--pkglist
4 PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
6 # default options
7 lint=0 mode=pkglist
9 usage() {
10 printf >&2 'usage: %s [--srcinfo] [--lint] [--config <file>]' "$argv0"
11 exit 1
14 # mollyguard for sourcing PKGBUILDs
15 if (( UID == 0 )) && [[ ! -v AUR_ASROOT ]]; then
16 printf >&2 'warning: aur-%s is not meant to be run as root.\n' "$argv0"
17 printf >&2 'warning: To proceed anyway, set the %s variable.\n' 'AUR_ASROOT'
18 exit 1
21 source /usr/share/makepkg/util/option.sh
22 source /usr/share/makepkg/util/parseopts.sh
23 source /usr/share/makepkg/util/config.sh
24 source /usr/share/makepkg/util/util.sh
26 # option parsing
27 opt_short='p:'
28 opt_long=('buildscript:' 'config:' 'lint' 'srcinfo')
29 opt_hidden=('dump-options')
31 if ! parseopts "$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
32 usage
34 set -- "${OPTRET[@]}"
36 unset buildscript build_user makepkg_conf
37 while true; do
38 case "$1" in
39 -p|--buildscript)
40 shift; buildscript=$1 ;;
41 --config)
42 shift; makepkg_conf=$1 ;;
43 --srcinfo)
44 mode=srcinfo ;;
45 --lint)
46 lint=1 ;;
47 --dump-options)
48 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
49 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
50 exit ;;
51 --) shift; break ;;
52 esac
53 shift
54 done
56 # Sourcing the PKGBUILD should be done without set -e or other modes
57 # to match makepkg behavior (e.g. aur/cemu, aur/nicotine-plus-git)
58 # shellcheck disable=SC1090
59 source_safe "${buildscript-PKGBUILD}"
60 PKGDEST=${PKGDEST:-$PWD}
61 pkgbase=${pkgbase:-${pkgname[0]}}
63 # PKGEXT (packagelist), CARCH (lint)
64 load_makepkg_config "${makepkg_conf-}"
66 if (( lint )); then
67 source /usr/share/makepkg/lint_pkgbuild.sh
68 lint_pkgbuild
71 case $mode in
72 pkglist)
73 source /usr/share/makepkg/util/pkgbuild.sh
74 print_all_package_names
76 srcinfo)
77 source /usr/share/makepkg/srcinfo.sh
78 write_srcinfo_content
80 esac