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 15:37:40 +00:00
|
|
|
cfg_workdir="/tmp/$USER/zpac"
|
2015-01-27 16:52:45 +00:00
|
|
|
cfg_aur_api='https://aur.archlinux.org/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>.
|
|
|
|
-d Get the package sources (default).
|
|
|
|
EOF
|
|
|
|
}
|
2015-01-27 15:37:40 +00:00
|
|
|
|
|
|
|
aur.get() {
|
2015-01-27 16:52:45 +00:00
|
|
|
local aur_url
|
|
|
|
local tarball_url=$(package-query -1 -AS -f %u "$1")
|
|
|
|
local pkg_base=$( curl "${cfg_aur_api}?type=info&arg=${1}" | jshon -e results -e PackageBase )
|
2015-01-27 15:37:40 +00:00
|
|
|
|
|
|
|
cd "$cfg_workdir"
|
|
|
|
|
|
|
|
echo "Downloading $tarball_url"
|
2015-01-27 16:17:26 +00:00
|
|
|
{ curl -skL "$tarball_url" | gzip -d | tar x; } || {
|
2015-01-27 15:37:40 +00:00
|
|
|
err "Fail!"
|
|
|
|
return 1
|
|
|
|
}
|
2015-01-27 16:17:26 +00:00
|
|
|
|
2015-01-27 16:52:45 +00:00
|
|
|
echo ": ${cfg_workdir}/${pkg_base}"
|
2015-01-27 16:17:26 +00:00
|
|
|
|
|
|
|
if (( flag_get_deps )); then
|
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/[<>=]*}"
|
|
|
|
dep_repo=$(package-query -1 -AS -f '%r' "${dep_name}")
|
|
|
|
|
|
|
|
if [[ "$dep_repo" == 'aur' ]]; then
|
|
|
|
[[ -d "${cfg_workdir}/${dep_name}" ]]
|
|
|
|
aur.get "$dep_name" || { return "$?"; }
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2015-01-27 15:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
abs.get() {
|
|
|
|
local svn_repo
|
|
|
|
|
|
|
|
case "$package_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';;
|
2015-01-27 16:17:26 +00:00
|
|
|
-D) flag_get_deps=1;;
|
2015-01-27 15:37:40 +00:00
|
|
|
|
|
|
|
--) shift; break;;
|
|
|
|
-*)
|
|
|
|
err "Unknown key: $1"
|
|
|
|
usage
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
action=${action:-"get"}
|
|
|
|
|
|
|
|
package="$1"
|
|
|
|
|
|
|
|
case "$action" in
|
|
|
|
(get)
|
|
|
|
[[ -d "$cfg_workdir" ]] || {
|
|
|
|
mkdir -p "$cfg_workdir" || {
|
|
|
|
err "Can't create workdir: ${cfg_workdir}."
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IFS='/' read repo _ < <( package-query -AS -f '%r/%n' "$package" )
|
|
|
|
|
|
|
|
if [[ "$?" > 0 ]]; then
|
|
|
|
err "Can't find package: $package"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Found ${package} in ${repo}."
|
|
|
|
|
|
|
|
case "$repo" in
|
|
|
|
(aur)
|
|
|
|
aur.get "$package";;
|
|
|
|
|
|
|
|
(core|extra|community|multilib)
|
|
|
|
abs.get "$package";;
|
|
|
|
|
|
|
|
(*)
|
|
|
|
err "Repository $repo not supported."
|
|
|
|
return 1;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
(search)
|
|
|
|
package-query -ASs "$package"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|