91 lines
3.3 KiB
Bash
91 lines
3.3 KiB
Bash
#!/usr/bin/env bash
|
|
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
# You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
ZAURA_VERSION=0.1.4
|
|
|
|
zaura.version.print(){
|
|
printf "$ZAURA_VERSION"
|
|
}
|
|
|
|
zaura.aur.clone(){
|
|
if [ -z "$1" ]; then
|
|
echo -e "error: didn't specify package name";
|
|
exit 1;
|
|
else
|
|
for var in "${@:1}"; do
|
|
cd "$PKGCACHE" || sh -c 'printf "error: invalid directory '%s'" "$PKGCACHE" && exit 1'
|
|
git clone --quiet https://aur.archlinux.org/"$var".git 2>/dev/null
|
|
if [ -f "$PKGCACHE/$var/PKGBUILD" ]; then
|
|
printf "package '%s' cloned\n" "$var"
|
|
else
|
|
printf "error: aur package '%s' doesn't exist\n" "$var" && rm -rf "$PKGCACHE/${var:?}" && exit 1
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
zaura.aur.install(){
|
|
if [ -z "$1" ]; then
|
|
echo -e "error: didn't specify package name";
|
|
exit 1;
|
|
fi
|
|
for var in "${@:1}"; do
|
|
cd "$PKGCACHE/$var" || sh -c 'printf "error: invalid directory '%s'" "$PKGCACHE" && exit 1'
|
|
if [ -f "$PKGCACHE/$var/PKGBUILD" ]; then
|
|
makepkg -si "$MAKEPKGARGS"
|
|
else
|
|
printf "error: invalid aur package '%s' (missing pkgbuild)\n" "$var" && exit 1
|
|
fi
|
|
done
|
|
|
|
}
|
|
|
|
zaura.aur.webrpc.search(){
|
|
# No arguments
|
|
if [ -z "$1" ]; then
|
|
printf "error: no search argument provided\n";
|
|
exit 1;
|
|
else
|
|
# Search query
|
|
search="$(curl -s "https://aur.archlinux.org/rpc/?v=5&type=search&arg=${1}")"
|
|
# for loop (requires base64)
|
|
trap "printf 'error: search query not found\n' & exit 1" ERR;
|
|
for row in $(echo "$search" | jq -e -r '.results[] | @base64' || sh -c "printf 'error: search query not found or too large\n' && exit 1"); do
|
|
# function to simplify stuff
|
|
function jq2 {
|
|
echo "$row" | base64 --decode 2>/dev/null | jq -r "$1" 2>/dev/null;
|
|
}
|
|
# Set package info as variables for client
|
|
zaura_webrpc_packageName="$(echo "$search" | jq2 '.Name')"
|
|
zaura_webrpc_packageMaintainer="$(jq2 '.Maintainer')"
|
|
zaura_webrpc_packageDescription="$(jq2 '.Description')"
|
|
zaura_webrpc_packageVersion="$(jq2 '.Version')"
|
|
zaura_webrpc_packageUpstream="$(jq2 '.URL')"
|
|
zaura_webrpc_packageFirstSubmitted="$(jq2 '.FirstSubmitted')"
|
|
zaura_webrpc_packageID="$(jq2 '.ID')"
|
|
zaura_webrpc_packageLastModified="$(jq2 '.LastModified')"
|
|
zaura_webrpc_packageNumVotes="$(jq2 '.NumVotes')"
|
|
zaura_webrpc_packageOutOfDate="$(jq2 '.OutOfDate')"
|
|
zaura_webrpc_packagePackageBaseID="$(jq2 '.PackageBaseID')"
|
|
zaura_webrpc_packagePackageBase="$(jq2 '.PackageBase')"
|
|
zaura_webrpc_packageURLPath="$(jq2 '.URLPath')"
|
|
zaura_webrpc_packagePopularity="$(jq2 '.Popularity')"
|
|
zaura.aur.webrpc.search.print
|
|
# finished
|
|
done
|
|
fi;
|
|
}
|
|
|
|
zaura.aur.update() {
|
|
printf "starting aur package upgrade\n";
|
|
cd "$PKGCACHE" || sh -c "printf 'error: invalid directory %s' '$PKGCACHE' && exit 1";
|
|
for folder in *; do
|
|
if [ -f "$PKGCACHE/$folder/PKGBUILD" ]; then
|
|
cd "$PKGCACHE"/"$folder" || exit;
|
|
git pull
|
|
makepkg -si --needed;
|
|
fi
|
|
done
|
|
}
|