Add AUR package helper to ~/bin
This commit is contained in:
parent
aadab0a9b5
commit
15fde92d60
134
home/bin/baph
Executable file
134
home/bin/baph
Executable file
@ -0,0 +1,134 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple tool to update and install AUR packages for Arch Linux
|
||||||
|
#
|
||||||
|
# Written by Nathaniel Maia, September 2018
|
||||||
|
#
|
||||||
|
# This software is provided free of charge and WITHOUT warranty
|
||||||
|
|
||||||
|
|
||||||
|
declare -g PKGS=() # array of AUR packages
|
||||||
|
declare -g NOVIEW=0 # view the PKGBUILD of each AUR package
|
||||||
|
declare -g NOCONF=0 # no confirmation after viewing the PKGBUILD
|
||||||
|
declare -g BDIR="$HOME/.cache/aur_builds" # AUR build directory
|
||||||
|
declare -g AUR="https://aur.archlinux.org" # AUR address
|
||||||
|
|
||||||
|
readonly SCRIPT="$(readlink -f $0)"
|
||||||
|
readonly BASENAME="${0#*/}"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<- EOF
|
||||||
|
B.A.P.H - Basic AUR Package Helper
|
||||||
|
|
||||||
|
A simple and short script that allows installing and updating packages
|
||||||
|
|
||||||
|
USAGE: $NAME [OPTIONS] [PACKAGE]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
--help,-h Display this message
|
||||||
|
--update,-u Update all AUR packages on the system
|
||||||
|
--noview,-n Skip viewing the PKGBUILD for AUR packages
|
||||||
|
--noconfirm Skip confirmation after viewing the PKGBUILD
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$1" && exit ${2:-0}
|
||||||
|
}
|
||||||
|
|
||||||
|
comp() {
|
||||||
|
old="$(pacman -Qs "^$1$" | awk 'NR==1 {print $2}')"
|
||||||
|
new="$(curl --silent $AUR/packages/$1 | awk '/Details:/ {sub(/<\/h.?>/, ""); print $4}')"
|
||||||
|
[[ "$old" == "$new" ]] && return 0 || return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
buildp() {
|
||||||
|
local p="$1"
|
||||||
|
# evaluating the PKGBUILD could be dangerous but is short
|
||||||
|
# the user has either viewed and confirmed it or doesn't care and passed --noconfirm
|
||||||
|
eval "$(cat "$BDIR/$p/PKGBUILD")"
|
||||||
|
for d in ${depends[@]}; do
|
||||||
|
pacman -Ssq "^$d$" >/dev/null 2>&1 || $SCRIPT --noview --noconfirm "$d"
|
||||||
|
done
|
||||||
|
makepkg -sicr
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
sudo pacman -Syyu
|
||||||
|
local installed
|
||||||
|
installed="$(pacman -Qqm 2>/dev/null)"
|
||||||
|
if [[ $installed ]]; then
|
||||||
|
echo "Info: Updating AUR packages"
|
||||||
|
for p in $(echo $installed); do
|
||||||
|
comp "$p" && echo "$p -> up to date" || $SCRIPT --noview --noconfirm "$p"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "Info: No AUR packages installed..."
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
install() {
|
||||||
|
local p="$1"
|
||||||
|
|
||||||
|
if pacman -Qsq "^$p$" >/dev/null 2>&1; then
|
||||||
|
comp "$p" && echo "Warning: $p already installed and up to date"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "$BDIR/$p" >/dev/null 2>&1
|
||||||
|
mkdir -p "$BDIR/$p"
|
||||||
|
|
||||||
|
if ! git clone $AUR/$p.git $BDIR/$p; then
|
||||||
|
die "Error: Git clone failed" 1
|
||||||
|
elif [[ ! -e $BDIR/$p/PKGBUILD ]]; then
|
||||||
|
die "Error: $BDIR/$p is missing a PKGBUILD" 1
|
||||||
|
else
|
||||||
|
cd "$BDIR/$p"
|
||||||
|
|
||||||
|
if [[ $NOVIEW -eq 0 ]]; then
|
||||||
|
less -P " -- Viewing PKGBUILD for $p -- (press q to exit)" PKGBUILD
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $NOCONF -eq 0 ]]; then
|
||||||
|
printf "\n\nDo you want to continue installing $p? [Y/n]: " && read -r conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $NOCONF -eq 1 || $conf =~ [yY] ]]; then
|
||||||
|
buildp "$p"
|
||||||
|
else
|
||||||
|
echo "Info: Exiting $p build process early"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $HOME && rm -rf "$BDIR/$p" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! hash git curl >/dev/null 2>&1; then
|
||||||
|
die "Error: This requires git and curl installed" 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# command line arguments
|
||||||
|
for arg in $@; do case $arg in
|
||||||
|
--help|-h) usage ;;
|
||||||
|
--update|-u) update ;;
|
||||||
|
--noview|-n) NOVIEW=1 ;;
|
||||||
|
--noconfirm) NOCONF=1 ;;
|
||||||
|
*) PKGS+=($arg)
|
||||||
|
esac done
|
||||||
|
|
||||||
|
if [[ ${#PKGS[@]} -eq 0 ]]; then
|
||||||
|
die "Error: Requires at least one package to install" 2
|
||||||
|
else
|
||||||
|
for pkg in ${PKGS[@]}; do
|
||||||
|
if pacman -Ssq "^$pkg$" >/dev/null 2>&1; then
|
||||||
|
sudo pacman -S "$pkg"
|
||||||
|
elif curl --silent --head $AUR/packages/$pkg | head -n 1 | grep -q '200'; then
|
||||||
|
install "$pkg"
|
||||||
|
else
|
||||||
|
die "Error: Failed response from $AUR/packages/$pkg" 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
Reference in New Issue
Block a user