Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
8ba3c36d4a | |||
3d960cd6e4 | |||
048d64fc46 | |||
b484a167f4 | |||
40f797ac20 | |||
1fdde28724 | |||
5cd8546ece | |||
e0b175f496 |
@@ -8,3 +8,5 @@ A very simple AUR/ABS helper. Doesn't build packages, only gets the sources.
|
|||||||
-h Show this message.
|
-h Show this message.
|
||||||
-s Search for <package>.
|
-s Search for <package>.
|
||||||
-d Get the package sources (default).
|
-d Get the package sources (default).
|
||||||
|
|
||||||
|
You can override any value in the script in \$HOME/.config/zpac.rc.sh
|
||||||
|
116
zpac
116
zpac
@@ -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; }
|
||||||
@@ -17,43 +19,88 @@ usage() {
|
|||||||
-h Show this message.
|
-h Show this message.
|
||||||
-s Search for <package>.
|
-s Search for <package>.
|
||||||
-d Get the package sources (default).
|
-d Get the package sources (default).
|
||||||
|
-D If used with -d, makes $_self download the dependencies from AUR too.
|
||||||
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
|
||||||
|
printf 'aur/%s\n %s\n' "${aur_search_results[${i}]}" "$( jshon -e results -e $i -e Description -u <<< "$aur_api_search_data" )"
|
||||||
|
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 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" )
|
||||||
|
|
||||||
cd "$cfg_workdir"
|
cd "$cfg_workdir"
|
||||||
|
|
||||||
echo "Downloading $tarball_url"
|
echo "Downloading ${cfg_aur_url}${tarball_path}"
|
||||||
{ curl -skL "$tarball_url" | gzip -d | tar x; } || {
|
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
|
||||||
err "Fail!"
|
err "Fail!"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
echo ": ${cfg_workdir}/${pkg_group}"
|
echo ": ${cfg_workdir}/${pkg_base}"
|
||||||
|
|
||||||
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
|
||||||
|
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 "$?"
|
||||||
|
}
|
||||||
|
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,6 +111,10 @@ 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;;
|
--help|-h) usage; return 0;;
|
||||||
@@ -86,7 +137,12 @@ main() {
|
|||||||
|
|
||||||
action=${action:-"get"}
|
action=${action:-"get"}
|
||||||
|
|
||||||
|
if [[ "$1" ]]; then
|
||||||
package="$1"
|
package="$1"
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
(get)
|
(get)
|
||||||
@@ -97,21 +153,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'
|
||||||
|
else
|
||||||
|
while read; do
|
||||||
|
if [[ "$REPLY" =~ ^Repository ]]; then
|
||||||
|
repo="${REPLY##* }"
|
||||||
|
fi
|
||||||
|
done < <( pacman -Si "$package" )
|
||||||
|
|
||||||
|
[[ "$repo" ]] || {
|
||||||
|
err "Can't find package ${package}"
|
||||||
return 1
|
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 +186,17 @@ main() {
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
(search)
|
(search)
|
||||||
|
if type -P package-query &>/dev/null; then
|
||||||
package-query -ASs "$package"
|
package-query -ASs "$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
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user