12 Commits
v2.8 ... v3.2.1

Author SHA1 Message Date
fbt
a450ff9708 use aur4 by default 2015-06-22 13:31:03 +03:00
fbt
dd0d7f7902 support AUR 4 2015-06-10 14:15:52 +03:00
fbt
840ab9254c export instead of checkout 2015-05-22 17:53:16 +03:00
fbt
b2dc6c01d7 ughx2 2015-02-25 16:30:32 +03:00
fbt
c1490bb339 ugh 2015-02-25 16:22:45 +03:00
fbt
d26cd45116 rename the bloody script will ya 2015-02-25 16:20:42 +03:00
fbt
73004f978c zpac is now PRM 2015-02-25 16:17:02 +03:00
fbt
1c136aab43 Stop overriding echo, just use printf instead. 2015-02-20 17:50:36 +03:00
fbt
4351aa9450 Code cleanup, thanks to [stronny](https://github.com/stronny) 2015-02-20 17:34:46 +03:00
fbt
d19dc0fbb1 readarray! 2015-02-20 16:43:53 +03:00
fbt
b2cb42c371 a better usage function 2015-02-20 16:16:15 +03:00
fbt
95c0ffa43b better name foe the args normalizer 2015-02-13 12:20:45 +03:00
2 changed files with 92 additions and 71 deletions

View File

@@ -1,16 +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.
Usage: zpac [flags] <package> Usage: prm [flags] <package>
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. -S Search only in the sync db. Implies -s.
-A Search only in AUR. 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. -f Force downloading package sources even if they are already present in the working directory.
-w <dir> Set the working directory. -w <dir> Set the working directory.
You can override any value in the script in \$HOME/.config/zpac.rc.sh You can override any value in the script in \$HOME/.config/prm.rc.sh
By default zpac downloads the sources into the current directory. Controlled by `$cfg_workdir`. By default prm downloads the sources into the current directory. Controlled by `$cfg_workdir`.

View File

@@ -6,14 +6,16 @@
_self="${0##*/}" _self="${0##*/}"
cfg_workdir="$PWD" cfg_workdir="$PWD"
cfg_aur_url='https://aur.archlinux.org'
cfg_aur_api="${cfg_aur_url}/rpc.php"
echo() { printf '%s\n' "$*"; } # Version 4 by default.
err() { echo "$*" >&2; } cfg_aur_version='4'
err() { printf "$@" >&2; }
_cat() { while read -r; do printf '%s\n' "$REPLY"; done }
usage() { usage() {
while read; do echo "$REPLY"; done <<- EOF _cat <<- EOF
Usage: $_self [flags] <package> Usage: $_self [flags] <package>
Flags: Flags:
-h Show this message. -h Show this message.
@@ -27,72 +29,75 @@ usage() {
} }
aur.search() { aur.search() {
local aur_api_search_data aur_search_result_num pkg 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_api_search_data=$( curl -skL "${cfg_aur_api}?type=search&arg=${1}" )
aur_search_result_num=$( jshon -e resultcount -u <<< "$aur_api_search_data" ) aur_search_result_num=$( jshon -e resultcount -u <<< "$aur_api_search_data" )
if (( aur_search_result_num )); then # Exit if nothing was found
aur_search_results=( $( jshon -e results -a -e Name -u <<< "$aur_api_search_data" ) ) (( aur_search_result_num )) || { return 1; }
for i in "${!aur_search_results[@]}"; do aur_search_results=( $( jshon -e results -a -e Name -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" for i in "${!aur_search_results[@]}"; do
done {
else read -r version
return 1 read -r description
fi } < <(
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() { aur.info() {
local pkg_aur_info=$( curl -skL "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null ) declare pkg_aur_info aur_query_result
local aur_query_result=$( jshon -e resultcount -u <<< "$pkg_aur_info" )
if (( aur_query_result )); then pkg_aur_info=$( curl -skL "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null )
echo "$pkg_aur_info" aur_query_result=$( jshon -e resultcount -u <<< "$pkg_aur_info" )
else
return 1 (( aur_query_result )) || { return 1; }
fi
printf '%s' "$pkg_aur_info"
} }
aur.get() { aur.get() {
local dep_name aur_api_multireq aur_deps_api_data aur_deps_count aur_deps pkg_aur_info pkg_base tarball_path 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 read -r pkg_aur_info
{ # A temporary hack till AUR4 becomes the main version
read -r pkg_base if (( cfg_aur_version == 4 )); then
read -r tarball_path read -r pkg_base < <( jshon -e results -e PackageBase -u <<< "$pkg_aur_info" )
} < <( tarball_path="/cgit/aur.git/snapshot/${pkg_base}.tar.gz"
jshon -e results -e PackageBase -u -p -e URLPath -u <<< "$pkg_aur_info" else
) {
read -r pkg_base
read -r tarball_path
} < <(
jshon -e results -e PackageBase -u -p -e URLPath -u <<< "$pkg_aur_info"
)
fi
(( flag_force )) || { (( flag_force )) || {
[[ -d "${cfg_workdir}/${pkg_base}" ]] && { [[ -d "${cfg_workdir}/${pkg_base}" ]] && {
echo "Found ${pkg_base} in ${cfg_workdir}, skipping. Use -f to override." printf "Found %s in %s, skipping. Use -f to override\n" "${pkg_base}" "${cfg_workdir}"
return 17 return 17
} }
} }
cd "$cfg_workdir" cd "$cfg_workdir"
echo "Working in ${cfg_workdir}" printf "Working in %s\n" "${cfg_workdir}"
echo "Downloading ${pkg_base}" printf "Downloading %s\n" "${pkg_base}"
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || { { curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
err "Fail!" err "Fail!\n"
return 1 return 1
} }
if (( flag_get_deps )); then if (( flag_get_deps )); then
unset depends makedepends
cd "${cfg_workdir}/${pkg_base}" cd "${cfg_workdir}/${pkg_base}"
source PKGBUILD source PKGBUILD
@@ -105,7 +110,7 @@ aur.get() {
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" ) aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then if (( aur_deps_count )); then
echo "Getting dependencies for ${pkg_base}." printf "Getting dependencies for %s\n" "${pkg_base}"
aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) ) aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) )
@@ -113,10 +118,8 @@ aur.get() {
aur.get < <(aur.info "$i") aur.get < <(aur.info "$i")
_result="$?" _result="$?"
(( _result )) && { (( _result > 0 && result != 17 )) && {
(( _result == 17 )) || { return "$_result"
return "$_result"
}
} }
done done
fi fi
@@ -124,7 +127,7 @@ aur.get() {
} }
abs.get() { abs.get() {
local pkg_repo svn_repo declare pkg_repo svn_repo
pkg_repo="$2" pkg_repo="$2"
@@ -135,10 +138,10 @@ abs.get() {
svn_repo='packages';; svn_repo='packages';;
esac esac
svn checkout "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}" svn export "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}"
} }
args_norm() { set_argv() {
declare arg opt c declare arg opt c
declare -g argv declare -g argv
@@ -174,8 +177,8 @@ args_norm() {
} }
main() { main() {
if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then if [[ -f "$HOME/.config/prm.rc.sh" ]]; then
source "$HOME/.config/zpac.rc.sh" source "$HOME/.config/prm.rc.sh"
fi fi
while (( $# )); do while (( $# )); do
@@ -192,6 +195,14 @@ main() {
action='search' action='search'
flag_search_syncdb=1;; flag_search_syncdb=1;;
(-V)
cfg_aur_version="$2"
shift;;
(-u)
cfg_aur_url="$2"
shift;;
(-d) (-d)
if [[ "$action" == 'get' ]]; then if [[ "$action" == 'get' ]]; then
flag_get_deps=1 flag_get_deps=1
@@ -207,7 +218,7 @@ main() {
(-f) flag_force=1;; (-f) flag_force=1;;
(-*) (-*)
err "Unknown key: $1" err "Unknown key: %s\n" "$1"
usage usage
return 1 return 1
;; ;;
@@ -221,6 +232,16 @@ main() {
unset flag_search_aur flag_search_syncdb unset flag_search_aur flag_search_syncdb
} }
if [[ -z "$cfg_aur_url" ]]; then
if (( cfg_aur_version == 3 )); then
cfg_aur_url="https://aur.archlinux.org"
else
cfg_aur_url="https://aur4.archlinux.org"
fi
fi
cfg_aur_api="${cfg_aur_url}/rpc.php"
[[ "$action" ]] || { [[ "$action" ]] || {
usage usage
return 1 return 1
@@ -237,7 +258,7 @@ main() {
(get) (get)
[[ -d "$cfg_workdir" ]] || { [[ -d "$cfg_workdir" ]] || {
mkdir -p "$cfg_workdir" || { mkdir -p "$cfg_workdir" || {
err "Can't create workdir: ${cfg_workdir}." err "Can't create workdir: %s\n" "$cfg_workdir"
return 1 return 1
} }
} }
@@ -254,12 +275,12 @@ main() {
done < <( pacman -Si "$package" ) done < <( pacman -Si "$package" )
[[ "$repo" ]] || { [[ "$repo" ]] || {
err "Can't find package ${package}" err "Can't find package %s\n" "$package"
return 1 return 1
} }
fi fi
echo "Found ${package} in ${repo}." printf "Found %s in %s\n" "$package" "$repo"
case "$repo" in case "$repo" in
(aur) (aur)
@@ -269,7 +290,7 @@ main() {
abs.get "$package" "$repo";; abs.get "$package" "$repo";;
(*) (*)
err "Repository $repo not supported." err "Repository %s not supported\n" "$repo"
return 1;; return 1;;
esac esac
;; ;;
@@ -277,7 +298,7 @@ main() {
(search) (search)
if (( flag_search_aur )); then if (( flag_search_aur )); then
aur.search "$package" || { aur.search "$package" || {
err "No packages found." err "No packages found\n"
return 1 return 1
} }
elif (( flag_search_syncdb )); then elif (( flag_search_syncdb )); then
@@ -287,7 +308,7 @@ main() {
pacman -Ss "$package" 2>/dev/null || { flag_pacman_search_fail=1; } pacman -Ss "$package" 2>/dev/null || { flag_pacman_search_fail=1; }
if (( flag_aur_search_fail && flag_pacman_search_fail )); then if (( flag_aur_search_fail && flag_pacman_search_fail )); then
err "No packages found." err "No packages found\n"
return 1 return 1
fi fi
fi fi
@@ -295,5 +316,5 @@ main() {
esac esac
} }
args_norm "$@" set_argv "$@"
main "${argv[@]}" main "${argv[@]}"