12 Commits
v2.0 ... v2.5

Author SHA1 Message Date
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
2 changed files with 100 additions and 20 deletions

View File

@@ -7,4 +7,11 @@ A very simple AUR/ABS helper. Doesn't build packages, only gets the sources.
Flags:
-h Show this message.
-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 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`.

113
zpac
View File

@@ -5,7 +5,7 @@
_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"
@@ -18,8 +18,10 @@ usage() {
Flags:
-h Show this message.
-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 If used with -d, makes $_self download the dependencies from AUR too.
Set twice to also get the dependencies.
EOF
}
@@ -33,7 +35,14 @@ aur.search() {
aur_search_results=( $( jshon -e results -a -e Name -u <<< "$aur_api_search_data" ) )
for i in "${!aur_search_results[@]}"; do
printf 'aur/%s\n %s\n' "${aur_search_results[${i}]}" "$( jshon -e results -e $i -e Description -u <<< "$aur_api_search_data" )"
{
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
@@ -54,10 +63,14 @@ aur.info() {
aur.get() {
local dep_name aur_api_multireq aur_deps_api_data aur_deps_count aur_deps pkg_aur_info pkg_base tarball_path
read pkg_aur_info
read -r pkg_aur_info
pkg_base=$( jshon -e results -e PackageBase -u <<< "$pkg_aur_info" )
tarball_path=$( jshon -e results -e URLPath -u <<< "$pkg_aur_info" )
{
read -r pkg_base
read -r tarball_path
} < <(
jshon -e results -e PackageBase -u -p -e URLPath -u <<< "$pkg_aur_info"
)
cd "$cfg_workdir"
@@ -84,9 +97,7 @@ aur.get() {
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then
aur_deps=$( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" )
echo "${aur_deps[@]}"
aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) )
for i in "${aur_deps[@]}"; do
aur.get < <(aur.info "$i") || {
@@ -112,17 +123,67 @@ abs.get() {
svn checkout "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}"
}
args_norm() {
while (( $# )); do
unset -v arg opt c keys
case "$1" in
--) printf '%s\n' '--'; break;;
--*)
IFS='=' read -r arg opt <<< "$1"
printf '%s\n' "$arg"
[[ "$opt" ]] && {
printf '%s\n' "$opt"
}
;;
-*)
while read -r -n1 c
do
case "$c" in
-|'') :;;
*) keys+=( "-$c" );;
esac
done <<< "$1"
printf '%s\n' "${keys[@]}"
;;
*) printf '%s\n' "$1";;
esac
shift
done
}
main() {
if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then
source "$HOME/.config/zpac.rc.sh"
fi
while (( $# )); do
case "$1" in
--help|-h) usage; return 0;;
(-h) usage; return 0;;
-s) action='search';;
-d) action='get';;
-D) flag_get_deps=1;;
(-s) action='search';;
(-A)
action='search'
flag_search_aur=1;;
(-S)
action='search'
flag_search_syncdb=1;;
--) shift; break;;
-*)
(-d)
if [[ "$action" == 'get' ]]; then
flag_get_deps=1
else
action='get'
fi
;;
(--) shift; break;;
(-*)
err "Unknown key: $1"
usage
return 1
@@ -133,7 +194,14 @@ main() {
shift
done
action=${action:-"get"}
(( flag_search_aur && flag_search_syncdb )) && {
unset flag_search_aur flag_search_syncdb
}
[[ "$action" ]] || {
usage
return 1
}
if [[ "$1" ]]; then
package="$1"
@@ -156,7 +224,7 @@ main() {
if (( ! "$?" )); then
repo='aur'
else
while read; do
while read -r; do
if [[ "$REPLY" =~ ^Repository ]]; then
repo="${REPLY##* }"
fi
@@ -184,8 +252,13 @@ main() {
;;
(search)
if type -P package-query &>/dev/null; then
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; }
@@ -199,4 +272,4 @@ main() {
esac
}
main "$@"
main $(args_norm "$@")