summaryrefslogtreecommitdiff
path: root/src/lib/util
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2022-12-17 01:51:15 +0100
committerLevente Polyak <anthraxx@archlinux.org>2023-05-19 22:27:13 +0200
commit5752488ef114513c8f75d753cf91d5b61dfa0660 (patch)
tree53b3fb27b343838efa3bcd70412cedc1c470d957 /src/lib/util
parentb9db6160a2547a57d19308776a25223eb2130b6b (diff)
downloaddevtools-5752488ef114513c8f75d753cf91d5b61dfa0660.tar.xz
release: command to commit, tag and upload build artifacts
This is a smart and more convenient invocation of the classical commitpkg and archrelease with auto-discovery for target repositories and a shorthand option to directly call db-update.
Diffstat (limited to 'src/lib/util')
-rw-r--r--src/lib/util/pacman.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib/util/pacman.sh b/src/lib/util/pacman.sh
new file mode 100644
index 0000000..f6c2d5f
--- /dev/null
+++ b/src/lib/util/pacman.sh
@@ -0,0 +1,52 @@
+#!/hint/bash
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+[[ -z ${DEVTOOLS_INCLUDE_UTIL_PACMAN_SH:-} ]] || return 0
+DEVTOOLS_INCLUDE_UTIL_PACMAN_SH=1
+
+_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
+# shellcheck source=src/lib/common.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
+
+set -e
+
+
+readonly _DEVTOOLS_PACMAN_CACHE_DIR=${XDG_CACHE_DIR:-$HOME/.cache}/devtools/pacman/db
+readonly _DEVTOOLS_PACMAN_CONF_DIR=${_DEVTOOLS_LIBRARY_DIR}/pacman.conf.d
+readonly _DEVTOOLS_MAKEPKG_CONF_DIR=${_DEVTOOLS_LIBRARY_DIR}/makepkg.conf.d
+
+
+update_pacman_repo_cache() {
+ mkdir -p "${_DEVTOOLS_PACMAN_CACHE_DIR}"
+ msg "Updating pacman database cache"
+ lock 10 "${_DEVTOOLS_PACMAN_CACHE_DIR}.lock" "Locking pacman database cache"
+ fakeroot -- pacman --config "${_DEVTOOLS_PACMAN_CONF_DIR}/multilib.conf" \
+ --dbpath "${_DEVTOOLS_PACMAN_CACHE_DIR}" \
+ -Sy
+ lock_close 10
+}
+
+get_pacman_repo_from_pkgbuild() {
+ local path=${1:-PKGBUILD}
+
+ # shellcheck source=contrib/makepkg/PKGBUILD.proto
+ mapfile -t pkgnames < <(source "${path}"; printf "%s\n" "${pkgname[@]}")
+
+ if (( ${#pkgnames[@]} == 0 )); then
+ die 'Failed to get pkgname from %s' "${path}"
+ return
+ fi
+
+ slock 10 "${_DEVTOOLS_PACMAN_CACHE_DIR}.lock" "Locking pacman database cache"
+ mapfile -t repos < <(pacman --config "${_DEVTOOLS_PACMAN_CONF_DIR}/multilib.conf" \
+ --dbpath "${_DEVTOOLS_PACMAN_CACHE_DIR}" \
+ -S \
+ --print \
+ --print-format '%n %r' \
+ "${pkgnames[0]}" | grep -E "^${pkgnames[0]} " | awk '{print $2}'
+ )
+ lock_close 10
+
+ printf "%s" "${repos[0]}"
+}