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}\""