Compare commits

..

1 Commits

Author SHA1 Message Date
Levente Polyak
7a64d33b88 chore(license): avoid sourcing PKGBUILD in check subcommand
We don't actually need any data from the package, except the pkgbase
which is exclusively used during logging. Simply grep the pkgbase name
and use the path during early code path issues.

Component: pkgctl license check
2025-08-02 06:30:25 +02:00
2 changed files with 21 additions and 50 deletions

View File

@@ -8,8 +8,6 @@ DEVTOOLS_INCLUDE_DB_MOVE_SH=1
_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
# shellcheck source=src/lib/common.sh # shellcheck source=src/lib/common.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
# shellcheck source=src/lib/valid-repos.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh
set -e set -e
@@ -22,7 +20,6 @@ pkgctl_db_move_usage() {
Move packages between binary repositories. Move packages between binary repositories.
OPTIONS OPTIONS
--noconfirm Bypass any confirmation messages, should only be used with caution
-h, --help Show this help text -h, --help Show this help text
EXAMPLES EXAMPLES
@@ -32,12 +29,9 @@ _EOF_
} }
pkgctl_db_move() { pkgctl_db_move() {
if (( $# < 3 )); then local SOURCE_REPO=""
pkgctl_db_move_usage local TARGET_REPO=""
exit 1 local PKGBASES=()
fi
local CONFIRM=1
# option checking # option checking
while (( $# )); do while (( $# )); do
@@ -46,10 +40,6 @@ pkgctl_db_move() {
pkgctl_db_move_usage pkgctl_db_move_usage
exit 0 exit 0
;; ;;
--noconfirm)
CONFIRM=0
shift
;;
-*) -*)
die "invalid argument: %s" "$1" die "invalid argument: %s" "$1"
;; ;;
@@ -59,35 +49,16 @@ pkgctl_db_move() {
esac esac
done done
local source_repo=$1 if (( $# < 3 )); then
local target_repo=$2 pkgctl_db_move_usage
exit 1
fi
SOURCE_REPO=$1
TARGET_REPO=$2
shift 2 shift 2
PKGBASES+=("$@")
if ! in_array "${source_repo}" "${DEVTOOLS_VALID_REPOS[@]}"; then # shellcheck disable=SC2029
die "Invalid source repository: %s" "${source_repo}" ssh "${PACKAGING_REPO_RELEASE_HOST}" db-move "${SOURCE_REPO}" "${TARGET_REPO}" "${PKGBASES[@]}"
fi
if ! in_array "${target_repo}" "${DEVTOOLS_VALID_REPOS[@]}"; then
die "Invalid target repository: %s" "${target_repo}"
fi
if (( CONFIRM )); then
local pkglist
pkglist=$(printf '%s\n' "$@" | paste -sd ' ')
read -r -p "Move packages from [${source_repo}] to [${target_repo}]: ${pkglist}? [Y/n] " response
case ${response} in
[Yy][Ee][Ss]|[Yy]|'')
: # continue
;;
*)
exit 0
;;
esac
fi
local pkgbase
for pkgbase in "$@"; do
msg "Moving [%s] from [%s] to [%s]" "${pkgbase}" "${source_repo}" "${target_repo}"
# shellcheck disable=SC2046
db-move "${source_repo}" "${target_repo}" $(pacman -Sql "${source_repo}" | grep "^${pkgbase}" || echo "${pkgbase}")
done
} }

View File

@@ -94,19 +94,19 @@ pkgctl_license_check() {
pushd "${path}" >/dev/null pushd "${path}" >/dev/null
if [[ ! -f PKGBUILD ]]; then if [[ ! -f PKGBUILD ]]; then
msg_error "${BOLD}${pkgbase}:${ALL_OFF} no PKGBUILD found" msg_error "${BOLD}${path}:${ALL_OFF} no PKGBUILD found"
return 1 return 1
fi fi
# reset common PKGBUILD variables if [[ ! -f .SRCINFO ]]; then
unset pkgbase msg_error "${BOLD}${path}:${ALL_OFF} no .SRCINFO found"
return 1
# shellcheck source=contrib/makepkg/PKGBUILD.proto fi
if ! . ./PKGBUILD; then
msg_error "${BOLD}${pkgbase}:${ALL_OFF} failed to source PKGBUILD" if ! pkgbase=$(grep --max-count=1 --extended-regexp "pkgbase = (.+)" .SRCINFO | awk '{print $3}'); then
msg_error "${BOLD}${path}:${ALL_OFF} pkgbase not found in .SRCINFO"
return 1 return 1
fi fi
pkgbase=${pkgbase:-$pkgname}
if [[ ! -e LICENSE ]]; then if [[ ! -e LICENSE ]]; then
msg_error "${BOLD}${pkgbase}:${ALL_OFF} is missing the LICENSE file" msg_error "${BOLD}${pkgbase}:${ALL_OFF} is missing the LICENSE file"