Skip to content

Instantly share code, notes, and snippets.

@uobikiemukot
Last active August 31, 2015 05:55
Show Gist options
  • Save uobikiemukot/616527c88ab61c8898b9 to your computer and use it in GitHub Desktop.
Save uobikiemukot/616527c88ab61c8898b9 to your computer and use it in GitHub Desktop.
simple bash script for Archlinux AUR search/download
#!/bin/bash
BUILD_DIR="$HOME/build"
SEARCH_URL="https://aur.archlinux.org/rpc.php?type=search"
GIT_URL="https://aur.archlinux.org"
error()
{
echo $1
exit
}
search()
{
# require 'jq'
wget -qO - "${SEARCH_URL}&arg=$@" \
| jq '.results[]' \
| awk '
function split_and_gsub(str) {
split(str, a, ": ");
gsub(/",/, "", a[2]);
gsub(/"/, "", a[2]);
return a[2];
}
/"Description":/ {
desc = split_and_gsub($0);
}
/"Version":/ {
gsub(/,/, "", $0);
vers = split_and_gsub($0);
}
/"Name":/ {
name = split_and_gsub($0);
}
/^}/ {
printf "aur/" name " " vers "\n " desc "\n"
}'
}
download()
{
cd $BUILD_DIR || error "build directory not found"
for i in "$@"; do
git clone $GIT_URL/$i.git || error "download failed"
done
}
usage()
{
echo "usage: rua [-s|-d] package"
echo "-s: search"
echo "-d: download"
}
case $1 in
"-s")
shift
search $@;;
"-d")
shift
download $@;;
*)
usage;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment