diff options
author | Dave Reisner <dreisner@archlinux.org> | 2017-03-25 08:59:38 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2017-03-25 09:18:50 -0400 |
commit | c2b33327aa7b8faf3c88aeaa007e7eb4bba4869f (patch) | |
tree | 15b46e42eb771e2c095e31ba7e27ee3fe6dcab02 | |
parent | f638242d6e81b72f8e0ea11a4f8c3c84099fd5b6 (diff) | |
download | asp32-c2b33327aa7b8faf3c88aeaa007e7eb4bba4869f.tar.xz |
Handle split packages
When a basic lookup fails, attempt to resolve the package name through
archweb to get the pkgbase, under the assumption that this might be a
split package. This adds jq as a new dependency.
Closes #8.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | archweb.inc.sh | 9 | ||||
-rw-r--r-- | asp.in | 1 | ||||
-rw-r--r-- | package.inc.sh | 57 |
4 files changed, 52 insertions, 16 deletions
@@ -16,6 +16,7 @@ ZSH_COMPLETION = \ shell/zsh-completion INCLUDES = \ + archweb.inc.sh \ package.inc.sh \ remote.inc.sh \ util.inc.sh diff --git a/archweb.inc.sh b/archweb.inc.sh new file mode 100644 index 0000000..b660c29 --- /dev/null +++ b/archweb.inc.sh @@ -0,0 +1,9 @@ +archweb_get_pkgbase() { + local pkgbase + + pkgbase=$(curl -s "https://www.archlinux.org/packages/search/json/?q=$1" | + jq -r --arg pkgname "$1" 'limit(1; .results[] | select(.pkgname == $pkgname).pkgbase)') + [[ $pkgbase ]] || return 1 + + printf '%s\n' "$pkgbase" +} @@ -10,6 +10,7 @@ OPT_FORCE=0 m4_include(util.inc.sh) m4_include(remote.inc.sh) m4_include(package.inc.sh) +m4_include(archweb.inc.sh) usage() { cat<<EOF diff --git a/package.inc.sh b/package.inc.sh index a415415..a0515c9 100644 --- a/package.inc.sh +++ b/package.inc.sh @@ -1,13 +1,32 @@ +package_resolve() { + local pkgbase + + [[ -v pkgname ]] || log_fatal 'BUG: package_resolve called without pkgname var set' + + if package_find_remote "$1" "$2"; then + return 0 + fi + + if pkgbase=$(archweb_get_pkgbase "$1") && package_find_remote "$pkgbase" "$2"; then + log_info '%s is part of package %s' "$1" "$pkgbase" + printf -v pkgname %s "$pkgbase" + return 0 + fi + + log_error 'unknown package: %s' "$pkgname" +} + package_init() { - local do_update=1 pkgname=$1 + local do_update=1 if [[ $1 = -n ]]; then do_update=0 shift - pkgname=$1 fi - package_find_remote "$pkgname" "$2" || return 1 + pkgname=$1 + + package_resolve "$pkgname" "$2" || return 1 (( do_update )) || return 0 @@ -16,7 +35,7 @@ package_init() { } package_find_remote() { - local pkgname=$1 + pkgname=$1 # fastpath, checks local caches only for r in "${ARCH_GIT_REPOS[@]}"; do @@ -34,13 +53,12 @@ package_find_remote() { fi done - log_error 'unknown package: %s' "$pkgname" - return 1 } package_log() { - local pkgname=$1 method=$2 logargs remote + local method=$2 logargs remote + pkgname=$1 package_init "$pkgname" remote || return @@ -63,7 +81,8 @@ package_log() { } package_show_file() { - local pkgname=$1 file=${2:-PKGBUILD} remote repo subtree + local file=${2:-PKGBUILD} remote repo subtree + pkgname=$1 if [[ $pkgname = */* ]]; then IFS=/ read -r repo pkgname <<<"$pkgname" @@ -83,7 +102,8 @@ package_show_file() { } package_list_files() { - local pkgname=$1 remote + local remote + pkgname=$1 if [[ $pkgname = */* ]]; then IFS=/ read -r repo pkgname <<<"$pkgname" @@ -103,7 +123,8 @@ package_list_files() { } package_export() { - local pkgname=$1 remote repo arch path + local remote repo arch path + pkgname=$1 if [[ $pkgname = */* ]]; then IFS=/ read -r repo pkgname <<<"$pkgname" @@ -138,7 +159,8 @@ package_export() { } package_checkout() { - local pkgname=$1 remote + local remote + pkgname=$1 package_init "$pkgname" remote || return 1 @@ -152,8 +174,8 @@ package_checkout() { } package_get_repos_with_arch() { - local pkgname=$1 remote=$2 - local path arch repo + local remote=$2 path arch repo + pkgname=$1 while read -r path; do IFS=/- read -r _ repo arch <<<"$path" @@ -162,8 +184,9 @@ package_get_repos_with_arch() { } package_get_arches() { - local pkgname=$1 remote arch + local remote arch declare -A arches + pkgname=$1 package_init "$pkgname" remote || return 1 @@ -175,8 +198,9 @@ package_get_arches() { } package_get_repos() { - local pkgname=$1 remote repo + local remote repo declare -A repos + pkgname=$1 package_init "$pkgname" remote || return 1 @@ -188,7 +212,8 @@ package_get_repos() { } package_untrack() { - local pkgname=$1 remote=$2 + local remote=$2 + pkgname=$1 if git show-ref -q "refs/heads/$remote/packages/$pkgname"; then git branch -D "$remote/packages/$pkgname" |