repo-parse: remove unused import
[aurutils.git] / lib / aur-build--pkglist
blob7f5f14d7f7a74fb0c33b94442d062af428918882
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 # source follows $PATH, compute absolute path to PKGBUILD (#1115)
57 buildscript="$(realpath --strip -- "${buildscript-PKGBUILD}")"
59 # Sourcing the PKGBUILD should be done without set -e or other modes
60 # to match makepkg behavior (e.g. aur/cemu, aur/nicotine-plus-git)
61 # shellcheck disable=SC1090
62 source_safe "$buildscript"
63 PKGDEST=${PKGDEST:-$PWD}
64 pkgbase=${pkgbase:-${pkgname[0]}}
66 # PKGEXT (packagelist), CARCH (lint)
67 load_makepkg_config "${makepkg_conf-}"
69 if (( lint )); then
70 source /usr/share/makepkg/lint_pkgbuild.sh
71 lint_pkgbuild
74 case $mode in
75 pkglist)
76 source /usr/share/makepkg/util/pkgbuild.sh
77 print_all_package_names
79 srcinfo)
80 source /usr/share/makepkg/srcinfo.sh
81 write_srcinfo_content
83 esac