Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
0496e2c887 | |||
a450ff9708 | |||
dd0d7f7902 | |||
840ab9254c | |||
b2dc6c01d7 | |||
c1490bb339 | |||
d26cd45116 | |||
73004f978c | |||
1c136aab43 | |||
4351aa9450 | |||
d19dc0fbb1 | |||
b2cb42c371 | |||
95c0ffa43b | |||
8591081269 | |||
9e15b8200e | |||
bf18623e06 | |||
34775cfe97 | |||
9b3ea06c61 | |||
f8cfeac03c | |||
422adf3d47 | |||
07d1805d13 | |||
3d148e6b4a | |||
c8b1f67bdd | |||
d1becc7836 | |||
b68c7c5949 | |||
8e575157f7 | |||
7d778ecd66 | |||
aa8929ff8e | |||
2ab2fdd126 | |||
2c37b9e64e | |||
59432612de | |||
61a9cbd34d | |||
8ba3c36d4a | |||
3d960cd6e4 | |||
048d64fc46 |
16
README.md
16
README.md
@@ -1,10 +1,16 @@
|
|||||||
zpac
|
prm
|
||||||
----
|
---
|
||||||
A very simple AUR/ABS helper. Doesn't build packages, only gets the sources.
|
A very simple AUR/ABS helper. Doesn't build packages, only gets the sources.
|
||||||
|
|
||||||
$ zpac -h
|
Usage: prm [flags] <package>
|
||||||
Usage: zpac [flags] <package>
|
|
||||||
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.
|
||||||
|
|
||||||
|
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`.
|
||||||
|
297
prm
Executable file
297
prm
Executable file
@@ -0,0 +1,297 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Author: Jack L. Frost <fbt@fleshless.org>
|
||||||
|
# Licensed under the Internet Software Consortium (ISC) license.
|
||||||
|
# See LICENSE for its text.
|
||||||
|
|
||||||
|
_self="${0##*/}"
|
||||||
|
|
||||||
|
cfg_workdir="$PWD"
|
||||||
|
cfg_aur_url="https://aur.archlinux.org"
|
||||||
|
|
||||||
|
err() { printf "$@" >&2; }
|
||||||
|
|
||||||
|
_cat() { while read -r; do printf '%s\n' "$REPLY"; done }
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
_cat <<- EOF
|
||||||
|
Usage: $_self [flags] <package>
|
||||||
|
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). 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.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
aur.search() {
|
||||||
|
declare i aur_api_search_data aur_search_result_num aur_search_results version description
|
||||||
|
|
||||||
|
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" )
|
||||||
|
|
||||||
|
# Exit if nothing was found
|
||||||
|
(( aur_search_result_num )) || { return 1; }
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
aur.info() {
|
||||||
|
declare pkg_aur_info aur_query_result
|
||||||
|
|
||||||
|
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 )) || { return 1; }
|
||||||
|
|
||||||
|
printf '%s' "$pkg_aur_info"
|
||||||
|
}
|
||||||
|
|
||||||
|
aur.get() {
|
||||||
|
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
|
||||||
|
|
||||||
|
# A temporary hack till AUR4 becomes the main version
|
||||||
|
read -r pkg_base < <( jshon -e results -e PackageBase -u <<< "$pkg_aur_info" )
|
||||||
|
tarball_path="/cgit/aur.git/snapshot/${pkg_base}.tar.gz"
|
||||||
|
|
||||||
|
(( 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"
|
||||||
|
|
||||||
|
printf "Working in %s\n" "${cfg_workdir}"
|
||||||
|
|
||||||
|
printf "Downloading %s\n" "${pkg_base}"
|
||||||
|
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
|
||||||
|
err "Fail!\n"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (( flag_get_deps )); then
|
||||||
|
cd "${cfg_workdir}/${pkg_base}"
|
||||||
|
source PKGBUILD
|
||||||
|
|
||||||
|
for i in "${depends[@]}" "${makedepends[@]}"; do
|
||||||
|
dep_name="${i/[<>=]*}"
|
||||||
|
aur_api_multireq+="&arg\[\]=$dep_name"
|
||||||
|
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
|
||||||
|
printf "Getting dependencies for %s\n" "${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 > 0 && result != 17 )) && {
|
||||||
|
return "$_result"
|
||||||
|
}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
abs.get() {
|
||||||
|
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() {
|
||||||
|
declare arg opt c
|
||||||
|
declare -g argv
|
||||||
|
|
||||||
|
while (( $# )); do
|
||||||
|
unset -v arg opt c
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
(--) argv+=( "$1" ); break;;
|
||||||
|
|
||||||
|
(--*)
|
||||||
|
IFS='=' read arg opt <<< "$1"
|
||||||
|
argv+=( "$arg" )
|
||||||
|
|
||||||
|
[[ "$opt" ]] && {
|
||||||
|
argv+=( "$opt" )
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
|
||||||
|
(-*)
|
||||||
|
while read -n1 c
|
||||||
|
do
|
||||||
|
case "$c" in
|
||||||
|
-|'') :;;
|
||||||
|
*) argv+=( "-$c" );;
|
||||||
|
esac
|
||||||
|
done <<< "$1"
|
||||||
|
;;
|
||||||
|
|
||||||
|
(*) argv+=( "$1" );;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
if [[ -f "$HOME/.config/prm.rc.sh" ]]; then
|
||||||
|
source "$HOME/.config/prm.rc.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while (( $# )); do
|
||||||
|
case "$1" in
|
||||||
|
(--) shift; break;;
|
||||||
|
|
||||||
|
(-h) usage; return 0;;
|
||||||
|
|
||||||
|
(-s) action='search';;
|
||||||
|
(-A)
|
||||||
|
action='search'
|
||||||
|
flag_search_aur=1;;
|
||||||
|
(-S)
|
||||||
|
action='search'
|
||||||
|
flag_search_syncdb=1;;
|
||||||
|
|
||||||
|
(-u)
|
||||||
|
cfg_aur_url="$2"
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
(-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: %s\n" "$1"
|
||||||
|
usage
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
(*) break;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
(( flag_search_aur && flag_search_syncdb )) && {
|
||||||
|
unset flag_search_aur flag_search_syncdb
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg_aur_api="${cfg_aur_url}/rpc.php"
|
||||||
|
|
||||||
|
[[ "$action" ]] || {
|
||||||
|
usage
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ "$1" ]]; then
|
||||||
|
package="$1"
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$action" in
|
||||||
|
(get)
|
||||||
|
[[ -d "$cfg_workdir" ]] || {
|
||||||
|
mkdir -p "$cfg_workdir" || {
|
||||||
|
err "Can't create workdir: %s\n" "$cfg_workdir"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pkg_aur_info=$( aur.info "$package" )
|
||||||
|
|
||||||
|
if (( ! "$?" )); then
|
||||||
|
repo='aur'
|
||||||
|
else
|
||||||
|
while read -r; do
|
||||||
|
if [[ "$REPLY" =~ ^Repository ]]; then
|
||||||
|
repo="${REPLY##* }"
|
||||||
|
fi
|
||||||
|
done < <( pacman -Si "$package" )
|
||||||
|
|
||||||
|
[[ "$repo" ]] || {
|
||||||
|
err "Can't find package %s\n" "$package"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Found %s in %s\n" "$package" "$repo"
|
||||||
|
|
||||||
|
case "$repo" in
|
||||||
|
(aur)
|
||||||
|
aur.get <<< "$pkg_aur_info";;
|
||||||
|
|
||||||
|
(core|extra|community|multilib)
|
||||||
|
abs.get "$package" "$repo";;
|
||||||
|
|
||||||
|
(*)
|
||||||
|
err "Repository %s not supported\n" "$repo"
|
||||||
|
return 1;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
(search)
|
||||||
|
if (( flag_search_aur )); then
|
||||||
|
aur.search "$package" || {
|
||||||
|
err "No packages found\n"
|
||||||
|
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\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
set_argv "$@"
|
||||||
|
main "${argv[@]}"
|
202
zpac
202
zpac
@@ -1,202 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Author: Jack L. Frost <fbt@fleshless.org>
|
|
||||||
# Licensed under the Internet Software Consortium (ISC) license.
|
|
||||||
# See LICENSE for its text.
|
|
||||||
|
|
||||||
_self="${0##*/}"
|
|
||||||
|
|
||||||
cfg_workdir="/tmp/$USER/zpac"
|
|
||||||
cfg_aur_url='https://aur.archlinux.org'
|
|
||||||
cfg_aur_api="${cfg_aur_url}/rpc.php"
|
|
||||||
|
|
||||||
echo() { printf '%s\n' "$*"; }
|
|
||||||
err() { echo "$*" >&2; }
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
while read; do echo "$REPLY"; done <<- EOF
|
|
||||||
Usage: $_self [flags] <package>
|
|
||||||
Flags:
|
|
||||||
-h Show this message.
|
|
||||||
-s Search for <package>.
|
|
||||||
-d Get the package sources (default).
|
|
||||||
-D If used with -d, makes $_self download the dependencies from AUR too.
|
|
||||||
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() {
|
|
||||||
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
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
echo "Downloading ${cfg_aur_url}${tarball_path}"
|
|
||||||
{ 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
|
|
||||||
|
|
||||||
cd "${cfg_workdir}/${pkg_base}"
|
|
||||||
source PKGBUILD
|
|
||||||
|
|
||||||
for i in "${depends[@]}" "${makedepends[@]}"; do
|
|
||||||
dep_name="${i/[<>=]*}"
|
|
||||||
aur_api_multireq+="&arg\[\]=$dep_name"
|
|
||||||
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" )
|
|
||||||
|
|
||||||
echo "${aur_deps[@]}"
|
|
||||||
|
|
||||||
for i in "${aur_deps[@]}"; do
|
|
||||||
aur.get < <(aur.info "$i") || {
|
|
||||||
return "$?"
|
|
||||||
}
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
abs.get() {
|
|
||||||
local pkg_repo svn_repo
|
|
||||||
|
|
||||||
pkg_repo="$2"
|
|
||||||
|
|
||||||
case "$pkg_repo" in
|
|
||||||
(community|multilib)
|
|
||||||
svn_repo='community';;
|
|
||||||
(*)
|
|
||||||
svn_repo='packages';;
|
|
||||||
esac
|
|
||||||
|
|
||||||
svn checkout "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
while (( $# )); do
|
|
||||||
case "$1" in
|
|
||||||
--help|-h) usage; return 0;;
|
|
||||||
|
|
||||||
-s) action='search';;
|
|
||||||
-d) action='get';;
|
|
||||||
-D) flag_get_deps=1;;
|
|
||||||
|
|
||||||
--) shift; break;;
|
|
||||||
-*)
|
|
||||||
err "Unknown key: $1"
|
|
||||||
usage
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
|
|
||||||
*) break;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
action=${action:-"get"}
|
|
||||||
|
|
||||||
if [[ "$1" ]]; then
|
|
||||||
package="$1"
|
|
||||||
else
|
|
||||||
usage
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$action" in
|
|
||||||
(get)
|
|
||||||
[[ -d "$cfg_workdir" ]] || {
|
|
||||||
mkdir -p "$cfg_workdir" || {
|
|
||||||
err "Can't create workdir: ${cfg_workdir}."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg_aur_info=$( aur.info "$package" )
|
|
||||||
|
|
||||||
if (( ! "$?" )); then
|
|
||||||
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
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Found ${package} in ${repo}."
|
|
||||||
|
|
||||||
case "$repo" in
|
|
||||||
(aur)
|
|
||||||
aur.get <<< "$pkg_aur_info";;
|
|
||||||
|
|
||||||
(core|extra|community|multilib)
|
|
||||||
abs.get "$package" "$repo";;
|
|
||||||
|
|
||||||
(*)
|
|
||||||
err "Repository $repo not supported."
|
|
||||||
return 1;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
(search)
|
|
||||||
if type -P package-query &>/dev/null; then
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
Reference in New Issue
Block a user