Last active
August 31, 2015 05:55
-
-
Save uobikiemukot/616527c88ab61c8898b9 to your computer and use it in GitHub Desktop.
simple bash script for Archlinux AUR search/download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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