10 Commits
v2.4 ... v2.6

126
zpac
View File

@@ -20,8 +20,13 @@ usage() {
-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).
Set twice to also get the dependencies.
-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
}
@@ -35,7 +40,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
@@ -56,21 +68,32 @@ 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"
)
(( flag_force )) || {
[[ -d "${cfg_workdir}/${pkg_base}" ]] && {
echo "Found ${pkg_base} in ${cfg_workdir}, skipping. Use -f to override."
return 17
}
}
cd "$cfg_workdir"
echo "Downloading ${cfg_aur_url}${tarball_path}"
echo "Working in ${cfg_workdir}"
echo "Downloading ${pkg_base}"
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
err "Fail!"
return 1
}
echo ": ${cfg_workdir}/${pkg_base}"
if (( flag_get_deps )); then
unset depends makedepends
@@ -86,11 +109,18 @@ aur.get() {
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") || {
return "$?"
aur.get < <(aur.info "$i")
_result="$?"
(( _result )) && {
(( _result == 17 )) || {
return "$_result"
}
}
done
fi
@@ -112,44 +142,6 @@ 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
--) shift; break;;
--*)
IFS='=' read arg opt <<< "$1"
printf '%s\n' "$arg"
[[ "$opt" ]] && {
printf '%s\n' "$opt"
}
;;
-*)
while read -n1 c
do
case "$c" in
-|'') :;;
*) keys+=( "-$c" );;
esac
done <<< "$1"
printf '%s\n' "${keys[@]}"
;;
esac
[[ "$2" && ! "$2" =~ ^- ]] && {
printf '%s\n' "$2"
shift
}
shift
done
}
main() {
if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then
source "$HOME/.config/zpac.rc.sh"
@@ -157,17 +149,25 @@ main() {
while (( $# )); do
case "$1" in
(-h) usage; return 0;;
(--) shift; break;;
(-s) action='search';;
(-A)
(-*)
while read -n1 c
do
case "$c" in
(-|'') :;;
(h) usage; return 0;;
(s) action='search';;
(A)
action='search'
flag_search_aur=1;;
(-S)
(S)
action='search'
flag_search_syncdb=1;;
(-d)
(d)
if [[ "$action" == 'get' ]]; then
flag_get_deps=1
else
@@ -175,14 +175,22 @@ main() {
fi
;;
(--) shift; break;;
(-*)
(w)
cfg_workdir="$2"
shift;;
(f) flag_force=1;;
(*)
err "Unknown key: $1"
usage
return 1
;;
esac
done <<< "$1"
;;
*) break;;
(*) break;;
esac
shift
done
@@ -217,7 +225,7 @@ main() {
if (( ! "$?" )); then
repo='aur'
else
while read; do
while read -r; do
if [[ "$REPLY" =~ ^Repository ]]; then
repo="${REPLY##* }"
fi
@@ -265,4 +273,4 @@ main() {
esac
}
main $(args_norm "$@")
main "$@"