dotfiles/bin/getpkg
2024-04-01 12:06:39 +02:00

37 lines
910 B
Bash
Executable file

#!/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
;;
core|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}\""