2015-01-27 15:37:40 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-01-27 15:52:16 +00:00
|
|
|
# Author: Jack L. Frost <fbt@fleshless.org>
|
|
|
|
# Licensed under the Internet Software Consortium (ISC) license.
|
|
|
|
# See LICENSE for its text.
|
2015-01-27 15:37:40 +00:00
|
|
|
|
2015-01-27 15:41:12 +00:00
|
|
|
_self="${0##*/}"
|
|
|
|
|
2015-01-27 21:05:27 +00:00
|
|
|
cfg_workdir="$PWD"
|
2015-01-27 17:05:23 +00:00
|
|
|
cfg_aur_url='https://aur.archlinux.org'
|
|
|
|
cfg_aur_api="${cfg_aur_url}/rpc.php"
|
2015-01-27 15:37:40 +00:00
|
|
|
|
|
|
|
echo() { printf '%s\n' "$*"; }
|
|
|
|
err() { echo "$*" >&2; }
|
|
|
|
|
2015-01-27 15:41:12 +00:00
|
|
|
usage() {
|
|
|
|
while read; do echo "$REPLY"; done <<- EOF
|
|
|
|
Usage: $_self [flags] <package>
|
|
|
|
Flags:
|
|
|
|
-h Show this message.
|
|
|
|
-s Search for <package>.
|
2015-01-31 15:45:47 +00:00
|
|
|
-S Search only in the sync db. Implies -s.
|
|
|
|
-A Search only in AUR. Implies -s.
|
2015-01-27 15:41:12 +00:00
|
|
|
-d Get the package sources (default).
|
2015-01-31 15:45:47 +00:00
|
|
|
Set twice to also get the dependencies.
|
2015-02-06 08:25:36 +00:00
|
|
|
-f Force downloading package sources even if they are already present in the working directory.
|
2015-01-27 15:41:12 +00:00
|
|
|
EOF
|
|
|
|
}
|
2015-01-27 15:37:40 +00:00
|
|
|
|
2015-01-27 20:50:10 +00:00
|
|
|
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
|
2015-02-03 09:58:00 +00:00
|
|
|
{
|
|
|
|
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"
|
2015-01-27 20:50:10 +00:00
|
|
|
done
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-01-27 20:12:56 +00:00
|
|
|
aur.info() {
|
2015-01-27 20:50:10 +00:00
|
|
|
local pkg_aur_info=$( curl -skL "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null )
|
2015-01-27 20:12:56 +00:00
|
|
|
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
|
|
|
|
|
2015-02-03 09:58:00 +00:00
|
|
|
read -r pkg_aur_info
|
2015-01-27 20:12:56 +00:00
|
|
|
|
2015-02-03 09:58:00 +00:00
|
|
|
{
|
|
|
|
read -r pkg_base
|
|
|
|
read -r tarball_path
|
|
|
|
} < <(
|
|
|
|
jshon -e results -e PackageBase -u -p -e URLPath -u <<< "$pkg_aur_info"
|
|
|
|
)
|
2015-01-27 15:37:40 +00:00
|
|
|
|
2015-02-06 06:28:40 +00:00
|
|
|
(( flag_force )) || {
|
|
|
|
[[ -d "${cfg_workdir}/${pkg_base}" ]] && {
|
|
|
|
echo "Found ${pkg_base} in ${cfg_workdir}, skipping. Use -f to override."
|
|
|
|
return 17
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 15:37:40 +00:00
|
|
|
cd "$cfg_workdir"
|
|
|
|
|
2015-02-06 08:25:36 +00:00
|
|
|
echo "Working in ${cfg_workdir}"
|
|
|
|
|
|
|
|
echo "Downloading ${pkg_base}"
|
2015-01-27 17:05:23 +00:00
|
|
|
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
|
2015-01-27 15:37:40 +00:00
|
|
|
err "Fail!"
|
|
|
|
return 1
|
|
|
|
}
|
2015-01-27 16:17:26 +00:00
|
|
|
|
|
|
|
if (( flag_get_deps )); then
|
2015-01-27 20:12:56 +00:00
|
|
|
unset depends makedepends
|
|
|
|
|
2015-01-27 16:52:45 +00:00
|
|
|
cd "${cfg_workdir}/${pkg_base}"
|
2015-01-27 16:17:26 +00:00
|
|
|
source PKGBUILD
|
|
|
|
|
|
|
|
for i in "${depends[@]}" "${makedepends[@]}"; do
|
|
|
|
dep_name="${i/[<>=]*}"
|
2015-01-27 20:12:56 +00:00
|
|
|
aur_api_multireq+="&arg\[\]=$dep_name"
|
|
|
|
done
|
|
|
|
|
2015-01-27 20:50:10 +00:00
|
|
|
aur_deps_api_data=$( curl -skL "${cfg_aur_api}?type=multiinfo${aur_api_multireq}" )
|
2015-01-27 20:12:56 +00:00
|
|
|
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
|
2015-01-27 16:17:26 +00:00
|
|
|
|
2015-01-27 20:12:56 +00:00
|
|
|
if (( aur_deps_count )); then
|
2015-02-06 08:25:36 +00:00
|
|
|
echo "Getting dependencies for ${pkg_base}."
|
|
|
|
|
2015-01-29 09:35:07 +00:00
|
|
|
aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) )
|
2015-01-27 20:12:56 +00:00
|
|
|
|
|
|
|
for i in "${aur_deps[@]}"; do
|
2015-02-06 06:28:40 +00:00
|
|
|
aur.get < <(aur.info "$i")
|
|
|
|
_result="$?"
|
|
|
|
|
|
|
|
(( _result )) && {
|
|
|
|
(( _result == 17 )) || {
|
|
|
|
return "$_result"
|
|
|
|
}
|
2015-01-27 17:05:23 +00:00
|
|
|
}
|
2015-01-27 20:12:56 +00:00
|
|
|
done
|
|
|
|
fi
|
2015-01-27 16:17:26 +00:00
|
|
|
fi
|
2015-01-27 15:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
abs.get() {
|
2015-01-27 20:52:16 +00:00
|
|
|
local pkg_repo svn_repo
|
2015-01-27 15:37:40 +00:00
|
|
|
|
2015-01-27 20:52:16 +00:00
|
|
|
pkg_repo="$2"
|
|
|
|
|
|
|
|
case "$pkg_repo" in
|
2015-01-27 15:37:40 +00:00
|
|
|
(community|multilib)
|
|
|
|
svn_repo='community';;
|
|
|
|
(*)
|
|
|
|
svn_repo='packages';;
|
|
|
|
esac
|
|
|
|
|
|
|
|
svn checkout "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}"
|
|
|
|
}
|
|
|
|
|
2015-01-31 15:45:47 +00:00
|
|
|
args_norm() {
|
|
|
|
while (( $# )); do
|
|
|
|
unset -v arg opt c keys
|
|
|
|
|
|
|
|
case "$1" in
|
2015-01-31 15:54:41 +00:00
|
|
|
--) printf '%s\n' '--'; break;;
|
2015-01-31 15:45:47 +00:00
|
|
|
|
|
|
|
--*)
|
2015-02-03 09:58:00 +00:00
|
|
|
IFS='=' read -r arg opt <<< "$1"
|
2015-01-31 15:45:47 +00:00
|
|
|
printf '%s\n' "$arg"
|
|
|
|
|
|
|
|
[[ "$opt" ]] && {
|
|
|
|
printf '%s\n' "$opt"
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
|
|
|
|
-*)
|
2015-02-03 09:58:00 +00:00
|
|
|
while read -r -n1 c
|
2015-01-31 15:45:47 +00:00
|
|
|
do
|
|
|
|
case "$c" in
|
|
|
|
-|'') :;;
|
|
|
|
*) keys+=( "-$c" );;
|
|
|
|
esac
|
|
|
|
done <<< "$1"
|
|
|
|
|
|
|
|
printf '%s\n' "${keys[@]}"
|
|
|
|
;;
|
2015-02-01 14:27:39 +00:00
|
|
|
|
|
|
|
*) printf '%s\n' "$1";;
|
2015-01-31 15:45:47 +00:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-01-27 15:37:40 +00:00
|
|
|
main() {
|
2015-01-27 21:05:27 +00:00
|
|
|
if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then
|
|
|
|
source "$HOME/.config/zpac.rc.sh"
|
|
|
|
fi
|
|
|
|
|
2015-02-06 08:25:36 +00:00
|
|
|
while getopts 'sASdw:f' opt
|
|
|
|
do
|
|
|
|
case "$opt" in
|
|
|
|
(h) usage; return 0;;
|
2015-01-28 07:11:51 +00:00
|
|
|
|
2015-02-06 08:25:36 +00:00
|
|
|
(s) action='search';;
|
|
|
|
(A)
|
2015-01-28 07:11:51 +00:00
|
|
|
action='search'
|
|
|
|
flag_search_aur=1;;
|
2015-02-06 08:25:36 +00:00
|
|
|
(S)
|
2015-01-28 07:11:51 +00:00
|
|
|
action='search'
|
|
|
|
flag_search_syncdb=1;;
|
|
|
|
|
2015-02-06 08:25:36 +00:00
|
|
|
(d)
|
2015-01-31 15:45:47 +00:00
|
|
|
if [[ "$action" == 'get' ]]; then
|
|
|
|
flag_get_deps=1
|
|
|
|
else
|
|
|
|
action='get'
|
|
|
|
fi
|
|
|
|
;;
|
2015-01-28 07:11:51 +00:00
|
|
|
|
2015-02-06 08:25:36 +00:00
|
|
|
(w) cfg_workdir="$OPTARG";;
|
|
|
|
(f) flag_force=1;;
|
2015-02-06 06:28:40 +00:00
|
|
|
|
2015-02-06 08:25:36 +00:00
|
|
|
(\?)
|
|
|
|
err "Unknown key: $OPTARG"
|
2015-01-27 15:37:40 +00:00
|
|
|
usage
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
2015-02-06 08:25:36 +00:00
|
|
|
done shift $(( OPTIND - 1 ))
|
2015-01-27 15:37:40 +00:00
|
|
|
|
2015-01-28 07:11:51 +00:00
|
|
|
(( flag_search_aur && flag_search_syncdb )) && {
|
|
|
|
unset flag_search_aur flag_search_syncdb
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ "$action" ]] || {
|
|
|
|
usage
|
|
|
|
return 1
|
|
|
|
}
|
2015-01-27 15:37:40 +00:00
|
|
|
|
2015-01-27 20:12:56 +00:00
|
|
|
if [[ "$1" ]]; then
|
|
|
|
package="$1"
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
return 1
|
|
|
|
fi
|
2015-01-27 15:37:40 +00:00
|
|
|
|
|
|
|
case "$action" in
|
|
|
|
(get)
|
|
|
|
[[ -d "$cfg_workdir" ]] || {
|
|
|
|
mkdir -p "$cfg_workdir" || {
|
|
|
|
err "Can't create workdir: ${cfg_workdir}."
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 20:12:56 +00:00
|
|
|
pkg_aur_info=$( aur.info "$package" )
|
2015-01-27 15:37:40 +00:00
|
|
|
|
2015-01-27 20:12:56 +00:00
|
|
|
if (( ! "$?" )); then
|
|
|
|
repo='aur'
|
|
|
|
else
|
2015-02-03 09:58:00 +00:00
|
|
|
while read -r; do
|
2015-01-27 20:50:10 +00:00
|
|
|
if [[ "$REPLY" =~ ^Repository ]]; then
|
|
|
|
repo="${REPLY##* }"
|
|
|
|
fi
|
|
|
|
done < <( pacman -Si "$package" )
|
|
|
|
|
|
|
|
[[ "$repo" ]] || {
|
2015-01-27 20:12:56 +00:00
|
|
|
err "Can't find package ${package}"
|
|
|
|
return 1
|
|
|
|
}
|
2015-01-27 15:37:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Found ${package} in ${repo}."
|
|
|
|
|
|
|
|
case "$repo" in
|
|
|
|
(aur)
|
2015-01-27 20:12:56 +00:00
|
|
|
aur.get <<< "$pkg_aur_info";;
|
2015-01-27 15:37:40 +00:00
|
|
|
|
|
|
|
(core|extra|community|multilib)
|
2015-01-27 20:52:16 +00:00
|
|
|
abs.get "$package" "$repo";;
|
2015-01-27 15:37:40 +00:00
|
|
|
|
|
|
|
(*)
|
|
|
|
err "Repository $repo not supported."
|
|
|
|
return 1;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
(search)
|
2015-01-28 07:11:51 +00:00
|
|
|
if (( flag_search_aur )); then
|
|
|
|
aur.search "$package" || {
|
|
|
|
err "No packages found."
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
elif (( flag_search_syncdb )); then
|
|
|
|
pacman -Ss "$package"
|
2015-01-27 20:50:10 +00:00
|
|
|
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
|
2015-01-27 15:37:40 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2015-01-31 15:45:47 +00:00
|
|
|
main $(args_norm "$@")
|