24 Commits
v1.2 ... v2.6

Author SHA1 Message Date
fbt
34775cfe97 Readme update 2015-02-06 19:26:40 +03:00
fbt
9b3ea06c61 I'm on fire today. 2015-02-06 13:45:54 +03:00
fbt
f8cfeac03c And another bugfix. 2015-02-06 13:43:36 +03:00
fbt
422adf3d47 args_norm is not needed now.
+ a bugfix.
2015-02-06 13:42:10 +03:00
fbt
07d1805d13 I don't like getopts. Don't know why. I just don't. 2015-02-06 13:40:27 +03:00
fbt
3d148e6b4a Handle arguments with getopt: it supports arguments with spaces. 2015-02-06 11:25:36 +03:00
fbt
c8b1f67bdd Don't download existing sources 2015-02-06 09:28:40 +03:00
fbt
d1becc7836 Show versions in AUR searches, less jshon calls, read -r 2015-02-03 12:58:00 +03:00
fbt
b68c7c5949 A slight fix for the argument handler, doesn't really affect zpac in its current state. 2015-02-01 17:27:39 +03:00
fbt
8e575157f7 Handle -- properly 2015-01-31 18:54:41 +03:00
fbt
7d778ecd66 Better argument handling. 2015-01-31 18:45:47 +03:00
fbt
aa8929ff8e a fix for multiple dependencies. 2015-01-29 12:35:07 +03:00
fbt
2ab2fdd126 usage update 2015-01-28 10:38:56 +03:00
fbt
2c37b9e64e Mention cfg_workdir in the README 2015-01-28 10:13:07 +03:00
fbt
59432612de explicit and implicit action. Removed default one. 2015-01-28 10:11:51 +03:00
fbt
61a9cbd34d usage fix 2015-01-28 00:08:20 +03:00
fbt
8ba3c36d4a config support, README 2015-01-28 00:06:21 +03:00
fbt
3d960cd6e4 Config support 2015-01-28 00:05:27 +03:00
fbt
048d64fc46 stray debug message 2015-01-27 23:58:11 +03:00
fbt
b484a167f4 consistency 2015-01-27 23:52:16 +03:00
fbt
40f797ac20 Getting rid of package-query 2015-01-27 23:50:10 +03:00
fbt
1fdde28724 Use the API derectly. Massive speed boost. Almost as fast as cower \m/ 2015-01-27 23:12:56 +03:00
fbt
5cd8546ece fixes 2015-01-27 20:05:23 +03:00
fbt
e0b175f496 Ask the API for the package base 2015-01-27 19:52:45 +03:00
2 changed files with 191 additions and 36 deletions

View File

@@ -7,4 +7,11 @@ A very simple AUR/ABS helper. Doesn't build packages, only gets the sources.
Flags: Flags:
-h Show this message. -h Show this message.
-s Search for <package>. -s Search for <package>.
-S Search only in the sync db. Implies -s.
-A Search only in AUR. Implies -s.
-d Get the package sources (default). -d Get the package sources (default).
-D Get the dependencies also. Implies -d.
You can override any value in the script in \$HOME/.config/zpac.rc.sh
By default zpac downloads the sources into the current directory. Controlled by `$cfg_workdir`.

220
zpac
View File

@@ -5,7 +5,9 @@
_self="${0##*/}" _self="${0##*/}"
cfg_workdir="/tmp/$USER/zpac" cfg_workdir="$PWD"
cfg_aur_url='https://aur.archlinux.org'
cfg_aur_api="${cfg_aur_url}/rpc.php"
echo() { printf '%s\n' "$*"; } echo() { printf '%s\n' "$*"; }
err() { echo "$*" >&2; } err() { echo "$*" >&2; }
@@ -16,44 +18,121 @@ usage() {
Flags: Flags:
-h Show this message. -h Show this message.
-s Search for <package>. -s Search for <package>.
-d Get the package sources (default). -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.
-w <dir> Set the working directory.
Warning! Due to how the argument handling works, you can do this:
$ zpac -wdd /tmp/workdir package
Where /tmp/workdir is an argument to w. Don't do this. But it works, unfortunately.
EOF EOF
} }
aur.search() {
local aur_api_search_data aur_search_result_num pkg
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" )
if (( aur_search_result_num )); then
aur_search_results=( $( jshon -e results -a -e Name -u <<< "$aur_api_search_data" ) )
for i in "${!aur_search_results[@]}"; do
{
read -r version
read -r description
} < <(
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
else
return 1
fi
}
aur.info() {
local pkg_aur_info=$( curl -skL "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null )
local aur_query_result=$( jshon -e resultcount -u <<< "$pkg_aur_info" )
if (( aur_query_result )); then
echo "$pkg_aur_info"
else
return 1
fi
}
aur.get() { aur.get() {
local aur_url pkg_group tarball_url=$(package-query -1 -AS -f %u "$1") local dep_name aur_api_multireq aur_deps_api_data aur_deps_count aur_deps pkg_aur_info pkg_base tarball_path
IFS='/' read _ _ aur_url _ _ pkg_group _ <<< "$tarball_url"
read -r pkg_aur_info
{
read -r pkg_base
read -r tarball_path
} < <(
jshon -e results -e PackageBase -u -p -e URLPath -u <<< "$pkg_aur_info"
)
(( flag_force )) || {
[[ -d "${cfg_workdir}/${pkg_base}" ]] && {
echo "Found ${pkg_base} in ${cfg_workdir}, skipping. Use -f to override."
return 17
}
}
cd "$cfg_workdir" cd "$cfg_workdir"
echo "Downloading $tarball_url" echo "Working in ${cfg_workdir}"
{ curl -skL "$tarball_url" | gzip -d | tar x; } || {
echo "Downloading ${pkg_base}"
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
err "Fail!" err "Fail!"
return 1 return 1
} }
echo ": ${cfg_workdir}/${pkg_group}"
if (( flag_get_deps )); then if (( flag_get_deps )); then
cd "${cfg_workdir}/${pkg_group}" unset depends makedepends
cd "${cfg_workdir}/${pkg_base}"
source PKGBUILD source PKGBUILD
for i in "${depends[@]}" "${makedepends[@]}"; do for i in "${depends[@]}" "${makedepends[@]}"; do
dep_name="${i/[<>=]*}" dep_name="${i/[<>=]*}"
dep_repo=$(package-query -1 -AS -f '%r' "${dep_name}") aur_api_multireq+="&arg\[\]=$dep_name"
if [[ "$dep_repo" == 'aur' ]]; then
[[ -d "${cfg_workdir}/${dep_name}" ]]
aur.get "$dep_name" || { return "$?"; }
fi
done done
aur_deps_api_data=$( curl -skL "${cfg_aur_api}?type=multiinfo${aur_api_multireq}" )
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then
echo "Getting dependencies for ${pkg_base}."
aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) )
for i in "${aur_deps[@]}"; do
aur.get < <(aur.info "$i")
_result="$?"
(( _result )) && {
(( _result == 17 )) || {
return "$_result"
}
}
done
fi
fi fi
} }
abs.get() { abs.get() {
local svn_repo local pkg_repo svn_repo
case "$package_repo" in pkg_repo="$2"
case "$pkg_repo" in
(community|multilib) (community|multilib)
svn_repo='community';; svn_repo='community';;
(*) (*)
@@ -64,29 +143,73 @@ abs.get() {
} }
main() { main() {
if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then
source "$HOME/.config/zpac.rc.sh"
fi
while (( $# )); do while (( $# )); do
case "$1" in case "$1" in
--help|-h) usage; return 0;; (--) shift; break;;
-s) action='search';; (-*)
-d) action='get';; while read -n1 c
-D) flag_get_deps=1;; do
case "$c" in
(-|'') :;;
--) shift; break;; (h) usage; return 0;;
-*)
err "Unknown key: $1" (s) action='search';;
usage (A)
return 1 action='search'
flag_search_aur=1;;
(S)
action='search'
flag_search_syncdb=1;;
(d)
if [[ "$action" == 'get' ]]; then
flag_get_deps=1
else
action='get'
fi
;;
(w)
cfg_workdir="$2"
shift;;
(f) flag_force=1;;
(*)
err "Unknown key: $1"
usage
return 1
;;
esac
done <<< "$1"
;; ;;
*) break;; (*) break;;
esac esac
shift shift
done done
action=${action:-"get"} (( flag_search_aur && flag_search_syncdb )) && {
unset flag_search_aur flag_search_syncdb
}
package="$1" [[ "$action" ]] || {
usage
return 1
}
if [[ "$1" ]]; then
package="$1"
else
usage
return 1
fi
case "$action" in case "$action" in
(get) (get)
@@ -97,21 +220,31 @@ main() {
} }
} }
IFS='/' read repo _ < <( package-query -AS -f '%r/%n' "$package" ) pkg_aur_info=$( aur.info "$package" )
if [[ "$?" > 0 ]]; then if (( ! "$?" )); then
err "Can't find package: $package" repo='aur'
return 1 else
while read -r; do
if [[ "$REPLY" =~ ^Repository ]]; then
repo="${REPLY##* }"
fi
done < <( pacman -Si "$package" )
[[ "$repo" ]] || {
err "Can't find package ${package}"
return 1
}
fi fi
echo "Found ${package} in ${repo}." echo "Found ${package} in ${repo}."
case "$repo" in case "$repo" in
(aur) (aur)
aur.get "$package";; aur.get <<< "$pkg_aur_info";;
(core|extra|community|multilib) (core|extra|community|multilib)
abs.get "$package";; abs.get "$package" "$repo";;
(*) (*)
err "Repository $repo not supported." err "Repository $repo not supported."
@@ -120,7 +253,22 @@ main() {
;; ;;
(search) (search)
package-query -ASs "$package" if (( flag_search_aur )); then
aur.search "$package" || {
err "No packages found."
return 1
}
elif (( flag_search_syncdb )); then
pacman -Ss "$package"
else
aur.search "$package" || { flag_aur_search_fail=1; }
pacman -Ss "$package" 2>/dev/null || { flag_pacman_search_fail=1; }
if (( flag_aur_search_fail && flag_pacman_search_fail )); then
err "No packages found."
return 1
fi
fi
;; ;;
esac esac
} }