Compare commits

..

No commits in common. "master" and "v3.2" have entirely different histories.
master ... v3.2

2 changed files with 96 additions and 128 deletions

View File

@ -9,11 +9,8 @@ A very simple AUR/ABS helper. Doesn't build packages, only gets the sources.
-S Search only in the sync db. Implies -s. -S Search only in the sync db. Implies -s.
-A Search only in AUR. Implies -s. -A Search only in AUR. Implies -s.
-d Get the package sources (default). Set twice to also get the dependencies. -d Get the package sources (default). Set twice to also get the dependencies.
-n Don't update existing git repos. -f Force downloading package sources even if they are already present in the working directory.
-u Print out all (and download if -d/-dd) outdated AUR packages.
-U <url> Set AUR url.
-w <dir> Set the working directory. -w <dir> Set the working directory.
--nossl Set curl's --insecure flag.
You can override any value in the script in \$HOME/.config/prm.rc.sh You can override any value in the script in \$HOME/.config/prm.rc.sh
By default prm downloads the sources into the current directory. Controlled by `$cfg_workdir`. By default prm downloads the sources into the current directory. Controlled by `$cfg_workdir`.

219
prm
View File

@ -6,9 +6,9 @@
_self="${0##*/}" _self="${0##*/}"
cfg_workdir="$PWD" cfg_workdir="$PWD"
cfg_aur_url="https://aur.archlinux.org"
cfg_curl_opts=( '--silent' '--location' ) # Version 3 by default. For now
cfg_aur_version='3'
err() { printf "$@" >&2; } err() { printf "$@" >&2; }
@ -23,36 +23,38 @@ usage() {
-S Search only in the sync db. Implies -s. -S Search only in the sync db. Implies -s.
-A Search only in AUR. Implies -s. -A Search only in AUR. Implies -s.
-d Get the package sources (default). Set twice to also get the dependencies. -d Get the package sources (default). Set twice to also get the dependencies.
-n Don't update existing git repos. -f Force downloading package sources even if they are already present in the working directory.
-u Print out all (and download if -d/-dd) outdated AUR packages.
-U <url> Set AUR url.
-w <dir> Set the working directory. -w <dir> Set the working directory.
--nossl Set curl's --insecure flag.
EOF EOF
} }
aur.search() { aur.search() {
declare i aur_api_search_data aur_search_result_num version description declare i aur_api_search_data aur_search_result_num aur_search_results version description
aur_api_search_data=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}&type=search&arg=${1}" ) aur_api_search_data=$( curl -skL "${cfg_aur_api}?type=search&arg=${1}" )
aur_search_result_num=$( jshon -e resultcount -u <<< "$aur_api_search_data" ) aur_search_result_num=$( jshon -e resultcount -u <<< "$aur_api_search_data" )
# Exit if nothing was found # Exit if nothing was found
(( aur_search_result_num )) || { return 1; } (( aur_search_result_num )) || { return 1; }
while { aur_search_results=( $( jshon -e results -a -e Name -u <<< "$aur_api_search_data" ) )
read -r name
read -r version for i in "${!aur_search_results[@]}"; do
read -r description {
} do read -r version
printf '%s %s\n %s\n' "aur/$name" "$version" "$description" read -r description
done < <( jshon -C -e results -a -e Name -u -p -e Version -u -p -e Description -u <<< "$aur_api_search_data" ) } < <(
jshon -e results -e $i -e Version -u -p -e Description -u <<< "$aur_api_search_data"
)
printf '%s %s\n %s\n' "aur/${aur_search_results[$i]}" "$version" "$description"
done
} }
aur.info() { aur.info() {
declare pkg_aur_info aur_query_result declare pkg_aur_info aur_query_result
pkg_aur_info=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}&type=info&arg=${1}" 2>/dev/null ) pkg_aur_info=$( curl -skL "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null )
aur_query_result=$( jshon -e resultcount -u <<< "$pkg_aur_info" ) aur_query_result=$( jshon -e resultcount -u <<< "$pkg_aur_info" )
(( aur_query_result )) || { return 1; } (( aur_query_result )) || { return 1; }
@ -60,85 +62,51 @@ aur.info() {
printf '%s' "$pkg_aur_info" printf '%s' "$pkg_aur_info"
} }
aur.get_updates() {
declare -a foreign_packages updated_pkgs
declare aur_api_multireq aur_api_data aur_api_data_length n p u n_name n_version l_name l_version
read -d '' -r -a foreign_packages < <( pacman -Qqm )
for p in "${foreign_packages[@]}"; do
aur_api_multireq+="&arg\[\]=$p"
done
aur_api_data=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}&type=info${aur_api_multireq}" )
aur_api_data_length=$( jshon -e results -l <<< "$aur_api_data" )
(( aur_api_data_length-- ))
for (( n=0; n<=aur_api_data_length; n++ )); do
read -r n_name < <( jshon -e results -e "$n" -e Name -u <<< "$aur_api_data")
read -r n_version < <( jshon -e results -e "$n" -e Version -u <<< "$aur_api_data" )
read -r l_name l_version < <( pacman -Q "$n_name" )
if (( $(vercmp "$n_version" "$l_version") )); then
updated_pkgs+=( "$n_name" )
printf '%s\n' "$n_name"
fi
done
if ! (( ${#updated_pkgs[@]} )); then
printf 'No updates found\n'
return 0
fi
if (( flag_get )); then
for u in "${updated_pkgs[@]}"; do
aur.get < <( aur.info "$u" )
done
fi
}
aur.get() { aur.get() {
declare i pkg_aur_info pkg_base depends makedepends dep_name aur_api_multireq dep_name aur_deps_api_data aur_deps_count aur_deps declare i pkg_aur_info pkg_base tarball_path depends makedepends dep_name aur_api_multireq dep_name aur_deps_api_data aur_deps_count aur_deps
read -r pkg_aur_info read -r pkg_aur_info
read -r pkg_base < <( jshon -e results -a -e Name -u <<< "$pkg_aur_info" ) # A temporary hack till AUR4 becomes the main version
if (( cfg_aur_version == 4 )); then
read -r pkg_base < <( jshon -e results -e PackageBase -u <<< "$pkg_aur_info" )
tarball_path="/cgit/aur.git/snapshot/${pkg_base}.tar.gz"
else
{
read -r pkg_base
read -r tarball_path
} < <(
jshon -e results -e PackageBase -u -p -e URLPath -u <<< "$pkg_aur_info"
)
fi
(( 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" cd "$cfg_workdir"
printf 'Working in %s\n' "${cfg_workdir}"
if [[ -d "$pkg_base" ]]; then printf "Working in %s\n" "${cfg_workdir}"
if ! (( flag_nopull )); then
printf 'Updating %s\n' "$pkg_base" printf "Downloading %s\n" "${pkg_base}"
cd "$pkg_base" { curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
git pull || { err "Fail!\n"
err 'Fail!' return 1
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 if (( flag_get_deps )); then
cd "${cfg_workdir}/${pkg_base}" cd "${cfg_workdir}/${pkg_base}"
source PKGBUILD
read -d '' -r -a depends < <( for i in "${depends[@]}" "${makedepends[@]}"; do
jshon -Q -e results -a -e Depends -a -u <<< "$pkg_aur_info"
jshon -Q -e results -a -e MakeDepends -a -u <<< "$pkg_aur_info"
)
for i in "${depends[@]}"; do
dep_name="${i/[<>=]*}" dep_name="${i/[<>=]*}"
aur_api_multireq+="&arg\[\]=$dep_name" aur_api_multireq+="&arg\[\]=$dep_name"
done done
aur_deps_api_data=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}&type=info${aur_api_multireq}" ) aur_deps_api_data=$( curl -skL "${cfg_aur_api}?type=multiinfo${aur_api_multireq}" )
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" ) aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then if (( aur_deps_count )); then
@ -150,16 +118,27 @@ aur.get() {
aur.get < <(aur.info "$i") aur.get < <(aur.info "$i")
_result="$?" _result="$?"
if (( _result > 0 && result != 17 )); then (( _result > 0 && result != 17 )) && {
return "$_result" return "$_result"
fi }
done done
fi fi
fi fi
} }
abs.get() { abs.get() {
git clone "https://gitlab.archlinux.org/archlinux/packaging/packages/$1.git" "$cfg_workdir/$1" declare pkg_repo svn_repo
pkg_repo="$2"
case "$pkg_repo" in
(community|multilib)
svn_repo='community';;
(*)
svn_repo='packages';;
esac
svn export "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}"
} }
set_argv() { set_argv() {
@ -208,26 +187,27 @@ main() {
(-h) usage; return 0;; (-h) usage; return 0;;
(-s) flag_search=1;; (-s) action='search';;
(-A) (-A)
flag_search=1 action='search'
flag_search_aur=1;; flag_search_aur=1;;
(-S) (-S)
flag_search=1 action='search'
flag_search_syncdb=1;; flag_search_syncdb=1;;
(-U) (-V)
cfg_aur_url="$2" cfg_aur_version="$2"
shift;; shift;;
(-u) (-u)
flag_update=1;; cfg_aur_url="$2"
shift;;
(-d) (-d)
if (( flag_get )); then if [[ "$action" == 'get' ]]; then
flag_get_deps=1 flag_get_deps=1
else else
flag_get=1 action='get'
fi fi
;; ;;
@ -235,9 +215,7 @@ main() {
cfg_workdir="$2" cfg_workdir="$2"
shift;; shift;;
(-n) flag_nopull=1;; (-f) flag_force=1;;
(--nossl) cfg_curl_opts+=( '--insecure' );;
(-*) (-*)
err "Unknown key: %s\n" "$1" err "Unknown key: %s\n" "$1"
@ -254,37 +232,35 @@ main() {
unset flag_search_aur flag_search_syncdb unset flag_search_aur flag_search_syncdb
} }
cfg_aur_api="${cfg_aur_url}/rpc?v=5" if [[ -z "$cfg_aur_url" ]]; then
if (( cfg_aur_version == 3 )); then
if (( flag_search )); then cfg_aur_url="https://aur.archlinux.org"
action=search else
elif (( flag_update )); then cfg_aur_url="https://aur4.archlinux.org"
action=update fi
elif (( flag_get )); then
action=get
fi fi
if [[ "$1" ]]; then cfg_aur_api="${cfg_aur_url}/rpc.php"
package="$1"
fi
[[ "$action" ]] || { [[ "$action" ]] || {
usage usage
return 1 return 1
} }
[[ -d "$cfg_workdir" ]] || { if [[ "$1" ]]; then
mkdir -p "$cfg_workdir" || { package="$1"
err "Can't create workdir: %s\n" "$cfg_workdir" else
return 1 usage
} return 1
} fi
case "$action" in case "$action" in
(get) (get)
[[ "$package" ]] || { [[ -d "$cfg_workdir" ]] || {
usage mkdir -p "$cfg_workdir" || {
return 1 err "Can't create workdir: %s\n" "$cfg_workdir"
return 1
}
} }
pkg_aur_info=$( aur.info "$package" ) pkg_aur_info=$( aur.info "$package" )
@ -292,7 +268,11 @@ main() {
if (( ! "$?" )); then if (( ! "$?" )); then
repo='aur' repo='aur'
else else
read -r repo < <( pacman -Sp --print-format '%r' "$package" ) while read -r; do
if [[ "$REPLY" =~ ^Repository ]]; then
repo="${REPLY##* }"
fi
done < <( pacman -Si "$package" )
[[ "$repo" ]] || { [[ "$repo" ]] || {
err "Can't find package %s\n" "$package" err "Can't find package %s\n" "$package"
@ -316,11 +296,6 @@ main() {
;; ;;
(search) (search)
[[ "$package" ]] || {
usage
return 1
}
if (( flag_search_aur )); then if (( flag_search_aur )); then
aur.search "$package" || { aur.search "$package" || {
err "No packages found\n" err "No packages found\n"
@ -338,10 +313,6 @@ main() {
fi fi
fi fi
;; ;;
(update)
aur.get_updates
;;
esac esac
} }