A few improvements:

* Use the new RPC format to avoid sourcing the PKGBUILD.
* A separate switch for curl's insecure mode: --nossl.
* Clone the AUR git repos instead of downloading the targballs.
This commit is contained in:
Jack L. Frost 2015-09-21 14:14:54 +03:00
parent 0496e2c887
commit e7252333b0
1 changed files with 34 additions and 23 deletions

57
prm
View File

@ -8,6 +8,8 @@ _self="${0##*/}"
cfg_workdir="$PWD"
cfg_aur_url="https://aur.archlinux.org"
cfg_curl_opts=( '--silent' '--location' )
err() { printf "$@" >&2; }
_cat() { while read -r; do printf '%s\n' "$REPLY"; done }
@ -21,7 +23,7 @@ usage() {
-S Search only in the sync db. Implies -s.
-A Search only in AUR. Implies -s.
-d Get the package sources (default). Set twice to also get the dependencies.
-f Force downloading package sources even if they are already present in the working directory.
-n Don't update existing git repos.
-w <dir> Set the working directory.
EOF
}
@ -29,7 +31,7 @@ usage() {
aur.search() {
declare i aur_api_search_data aur_search_result_num aur_search_results version description
aur_api_search_data=$( curl -skL "${cfg_aur_api}?type=search&arg=${1}" )
aur_api_search_data=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}?type=search&arg=${1}" )
aur_search_result_num=$( jshon -e resultcount -u <<< "$aur_api_search_data" )
# Exit if nothing was found
@ -52,7 +54,7 @@ aur.search() {
aur.info() {
declare pkg_aur_info aur_query_result
pkg_aur_info=$( curl -skL "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null )
pkg_aur_info=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}?type=info&v=2&arg=${1}" 2>/dev/null )
aur_query_result=$( jshon -e resultcount -u <<< "$pkg_aur_info" )
(( aur_query_result )) || { return 1; }
@ -69,33 +71,40 @@ aur.get() {
read -r pkg_base < <( jshon -e results -e PackageBase -u <<< "$pkg_aur_info" )
tarball_path="/cgit/aur.git/snapshot/${pkg_base}.tar.gz"
(( flag_force )) || {
[[ -d "${cfg_workdir}/${pkg_base}" ]] && {
printf "Found %s in %s, skipping. Use -f to override\n" "${pkg_base}" "${cfg_workdir}"
return 17
}
}
cd "$cfg_workdir"
printf 'Working in %s\n' "${cfg_workdir}"
printf "Working in %s\n" "${cfg_workdir}"
printf "Downloading %s\n" "${pkg_base}"
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
err "Fail!\n"
return 1
}
if [[ -d "$pkg_base" ]]; then
if ! (( flag_nopull )); then
printf 'Updating %s\n' "$pkg_base"
cd "$pkg_base"
git pull || {
err 'Fail!'
return 21
}
fi
else
printf 'Cloning %s\n' "$pkg_base"
git clone "https://aur.archlinux.org/${pkg_base}.git" || {
err 'Fail!'
return 19
}
fi
if (( flag_get_deps )); then
cd "${cfg_workdir}/${pkg_base}"
source PKGBUILD
for i in "${depends[@]}" "${makedepends[@]}"; do
read -d '' -r -a depends < <(
jshon -e results -e Depends -a -u -p -p -e MakeDepends -a -u <<< "$pkg_aur_info" 2>/dev/null
)
for i in "${depends[@]}"; do
dep_name="${i/[<>=]*}"
aur_api_multireq+="&arg\[\]=$dep_name"
done
aur_deps_api_data=$( curl -skL "${cfg_aur_api}?type=multiinfo${aur_api_multireq}" )
aur_deps_api_data=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}?type=multiinfo${aur_api_multireq}" )
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then
@ -107,9 +116,9 @@ aur.get() {
aur.get < <(aur.info "$i")
_result="$?"
(( _result > 0 && result != 17 )) && {
if (( _result > 0 && result != 17 )); then
return "$_result"
}
fi
done
fi
fi
@ -200,7 +209,9 @@ main() {
cfg_workdir="$2"
shift;;
(-f) flag_force=1;;
(-n) flag_nopull=1;;
(--nossl) cfg_curl_opts+=( '--insecure' );;
(-*)
err "Unknown key: %s\n" "$1"