init
This commit is contained in:
commit
94641417c7
96
zpac
Executable file
96
zpac
Executable file
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cfg_workdir="/tmp/$USER/zpac"
|
||||
|
||||
echo() { printf '%s\n' "$*"; }
|
||||
err() { echo "$*" >&2; }
|
||||
|
||||
usage() { echo "No help available."; }
|
||||
|
||||
aur.get() {
|
||||
local tarball_url=$(package-query -1 -AS -f %u "$1")
|
||||
|
||||
cd "$cfg_workdir"
|
||||
|
||||
echo "Downloading $tarball_url"
|
||||
{ curl "$tarball_url" | gzip -d | tar x; } || {
|
||||
err "Fail!"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
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';;
|
||||
|
||||
--) 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 "$@"
|
Loading…
Reference in New Issue
Block a user