#!/usr/bin/env bash # AUR RPC helpers (v5) using curl + jq aur_rpc_get() { local url=$1 local curl_bin curl_bin=$(resolve_curl) "$curl_bin" -fsSL --connect-timeout 15 --max-time 60 "$url" } # Search AUR; prints: name|version|votes|popularity|desc (one per line) aur_search() { local query=$1 local by=${2:-$MIAUR_SEARCHBY} local encoded encoded=$(printf '%s' "$query" | jq -sRr @uri) local json json=$(aur_rpc_get "${MIAUR_AURRPC}/search/${encoded}?by=${by}") || return 1 local sort=${MIAUR_SORTBY:-votes} local jq_sort case "$sort" in votes) jq_sort='sort_by(.NumVotes) | reverse' ;; popularity) jq_sort='sort_by(.Popularity) | reverse' ;; name) jq_sort='sort_by(.Name)' ;; *) jq_sort='sort_by(.NumVotes) | reverse' ;; esac jq -r --argjson err 0 " if .type == \"error\" then empty else (.results // []) | ${jq_sort} | .[] | [.Name, .Version, (.NumVotes|tostring), (.Popularity|tostring), (.Description // \"\")] | join(\"|\") end " <<<"$json" } # Info for one package; prints JSON object or empty aur_info_json() { local name=$1 local encoded encoded=$(printf '%s' "$name" | jq -sRr @uri) local json json=$(aur_rpc_get "${MIAUR_AURRPC}/info?arg[]=${encoded}") || return 1 jq -c '.results[0] // empty' <<<"$json" } # Multi-info: args are package names. Prints JSON array of results. aur_multiinfo_json() { local args=() local n for n in "$@"; do args+=(--data-urlencode "arg[]=${n}") done [[ ${#args[@]} -eq 0 ]] && { echo '[]'; return 0; } local json local curl_bin curl_bin=$(resolve_curl) json=$("$curl_bin" -fsSL --connect-timeout 15 --max-time 60 -G "${MIAUR_AURRPC}/info" "${args[@]}") || return 1 jq -c '.results // []' <<<"$json" } # Check if package exists on AUR (exit 0 if yes) aur_exists() { local j j=$(aur_info_json "$1") || return 1 [[ -n $j && $j != null ]] } # Print human-readable info for a package (like pacman -Si for AUR) aur_print_info() { local name=$1 local j j=$(aur_info_json "$name") || return 1 [[ -z $j || $j == null ]] && return 1 jq -r ' "Repository : aur", "Name : \(.Name)", "Version : \(.Version)", "Description : \(.Description // "")", "URL : \(.URL // "")", "AUR URL : https://aur.archlinux.org/packages/\(.Name)", "Groups : \((.Groups // []) | join(" "))", "Depends On : \((.Depends // []) | join(" "))", "Make Depends : \((.MakeDepends // []) | join(" "))", "Check Depends : \((.CheckDepends // []) | join(" "))", "Optional Deps : \((.OptDepends // []) | join(" "))", "Provides : \((.Provides // []) | join(" "))", "Conflicts With : \((.Conflicts // []) | join(" "))", "Replaces : \((.Replaces // []) | join(" "))", "Maintainer : \(.Maintainer // "(orphan)")", "Votes : \(.NumVotes)", "Popularity : \(.Popularity)", "Last Modified : \(.LastModified)", "Out Of Date : \(if .OutOfDate then (.OutOfDate|tostring) else "No" end)" ' <<<"$j" } # Print search line for AUR result: aur/name version (votes) desc aur_format_search_line() { local name=$1 ver=$2 votes=$3 desc=$5 local installed= if is_pkg_installed "$name"; then local localver localver=$(pkg_local_version "$name") if [[ $localver == "$ver" ]]; then installed=" ${C_GREEN}[installed]${C_RESET}" else installed=" ${C_YELLOW}[installed: ${localver}]${C_RESET}" fi fi printf '%saur/%s%s %s%s (%s)%s\n %s\n' \ "${C_BOLD}${C_CYAN}" "$name" "${C_RESET}" \ "${C_BOLD}${C_GREEN}${ver}${C_RESET}" \ "$installed" \ "$votes" \ "" \ "$desc" }