From 94f97e32a385fcdb1b66f3ba0b7cc1a6851269c3 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Thu, 7 Mar 2024 14:12:58 +0100 Subject: [PATCH] Ajout : script getpkg --- bin/getpkg | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 bin/getpkg diff --git a/bin/getpkg b/bin/getpkg new file mode 100755 index 0000000..5cd5cfc --- /dev/null +++ b/bin/getpkg @@ -0,0 +1,37 @@ +#!/usr/bin/env sh + +get_field() { + echo "$2" | cut -d / -f "$1" +} + +error() { + exit_code="$1" + shift + >&2 printf '\033[1;31m==> ERROR:\033[0m \033[1m%s\033[0m\n' "$*" + exit "$exit_code" +} + + repo=$(get_field 1 "$1") +package=$(get_field 2 "$1") + +case "$repo" in + system|world|galaxy|lib32) + url=gitea.artixlinux.org/packages/%s/raw/branch/master/PKGBUILD + ;; + extra|multilib) + #url=gitlab.archlinux.org/archlinux/packaging/packages + url=gitlab.archlinux.org/archlinux/packaging/packages/%s/-/raw/main/PKGBUILD + ;; + aur) + url='aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=%s' + ;; + *) + error 1 "Invalid repository name \"${repo}\"" + ;; +esac + +# Format is in my variable +# shellcheck disable=2059 +url=$(printf "https://${url}" "$package") + +curl -f -L -- "$url" || error 2 "Failed to retrieve PKGBUILD from \"${url}\""