#!/usr/bin/env sh ######################### # (c) archibold.io 2020 # ######################### aur() { local build="" local help="" local list="" local pkg="" local preserve="" local remove="" local skippgp="" local update="" local HAS_SUDO=0 for var in "$@"; do if [ "$var" = "--no-pgp" ] || [ "$var" = "--skippgpcheck" ]; then skippgp="--skippgpcheck" elif [ "$var" = "--preserve" ]; then preserve="--preserve" elif [ "$var" = "--list" ]; then list="--list" elif [ "$var" = "--remove" ]; then remove="--remove" elif [ "$var" = "--update" ]; then update="--update" elif [ "${var:0:1}" != "-" ]; then pkg="$var" else help="--help" fi done if [ "$(which sudo 2> /dev/null)" != "" ]; then HAS_SUDO=1 fi if [ "$USER" = "root" ]; then echo "" echo "You $(tput bold)cannot be root$(tput sgr0) to run $(tput bold)aur$(tput sgr0)" echo "" elif [ "$list" = "--list" ]; then echo "" echo "$(tput bold)Listing AUR Packages$(tput sgr0)" pacman -Qm echo "" elif [ "$update" = "--update" ]; then echo "" echo "$(tput bold)Updating AUR Packages$(tput sgr0)" mkdir -p ~/tmp-aur for var in $(pacman -Qmq); do cd ~/tmp-aur curl -Ls https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=${var} -o ${var} source ./${var} help="$(pacman -Qm ${var})" if [ "${pkgname} ${pkgver}-${pkgrel}" != "${help}" ]; then if [ "$(echo "${help}" | sed "s/[^ ]* //; s/[0-9._-]*//g")" != "" ]; then echo "❌ ignoring $(tput bold)${pkgname}$(tput sgr0)" else echo "updating $(tput bold)${pkgname}$(tput sgr0) ${pkgver}-${pkgrel}" aur $skippgp $preserve $var fi else echo "✔ $(tput bold)${pkgname}$(tput sgr0) ${pkgver}-${pkgrel} already updated" fi done rm -rf ~/tmp-aur echo "" elif [ "${help}" = "--help" ] || [ "${pkg}" = "" ]; then echo "" echo "The $(tput bold)aur$(tput sgr0) utility from https://archibold.io" echo "$(tput dim)A minimalistic AUR installer alternative.$(tput sgr0)" echo "" echo " aur pamac-aur $(tput dim)# install a specific package$(tput sgr0)" echo " aur --preserve wpewebkit $(tput dim)# install keeping the build folder$(tput sgr0)" echo " aur --no-pgp expressvpn $(tput dim)# install ignoring PGP keys$(tput sgr0)" echo " aur --remove expressvpn $(tput dim)# remove a specific package$(tput sgr0)" echo "" echo " aur --list $(tput dim)# list all AUR packages$(tput sgr0)" echo " aur --update $(tput dim)# update AUR packages if different$(tput sgr0)" echo "" echo " yes \$ROOT_PASSWORD | aur package $(tput dim)# avoid sudo asking password$(tput sgr0)" echo "" echo "$(tput dim)The $(tput sgr0)--update$(tput dim) flag can use $(tput sgr0)--no-pgp$(tput dim) or $(tput sgr0)--preserve$(tput dim) too.$(tput sgr0)" echo "$(tput dim)The $(tput sgr0)--skippgpcheck$(tput dim) flag is a $(tput sgr0)--no-pgp$(tput dim) alias.$(tput sgr0)" echo "$(tput dim)Use $(tput sgr0)AUR_NO_SUDO=1$(tput dim) to force-use $(tput sgr0)su$(tput dim) instead.$(tput sgr0)" echo "" elif [ "$remove" = "--remove" ]; then if [ "$AUR_NO_SUDO" != "" ] || [ "$HAS_SUDO" = "0" ]; then su -c "yes y | pacman -R ${pkg}" else sudo sh -c "yes y | pacman -R ${pkg}" fi else if [ "${AUR_NO_SUDO}${HAS_SUDO}" = "1" ]; then echo "Checking $(tput bold)sudo$(tput sgr0) privileges" sudo ls > /dev/null fi if [ ! -f ~/.archibold-aur ]; then date > ~/.archibold-aur echo "Installing $(tput bold)base-devel$(tput sgr0) and $(tput bold)git$(tput sgr0)" if [ "$AUR_NO_SUDO" != "" ] || [ "$HAS_SUDO" = "0" ]; then su -c ' while ! pacman -S --needed --noconfirm base-devel git do : done' if [ "$HAS_SUDO" = "0" ]; then su -c 'pacman -R --noconfirm sudo' fi else while ! sudo pacman -S --needed --noconfirm base-devel git do : done fi fi rm -rf ~/tmp-${pkg} echo "Creating ~/tmp-${pkg}" mkdir -p ~/tmp-${pkg} cd ~/tmp-${pkg} git clone https://aur.archlinux.org/${pkg}.git cd ${pkg} echo "Making $(tput bold)${pkg}$(tput sgr0) package" makepkg -Asfc --needed --noconfirm ${skippgp} echo "" if [ "$?" = "0" ]; then build="$(ls ${pkg}*.pkg.tar.{xz,zst} 2> /dev/null)" if [ "$build" != "" ]; then echo "$(tput bold)Created$(tput sgr0): ~/tmp-${pkg}/${pkg}/${build}" sync if [ "$AUR_NO_SUDO" != "" ] || [ "$HAS_SUDO" = "0" ]; then su -c "yes y | pacman -U ${build}" else sudo sh -c "yes y | pacman -U ${build}" fi fi else echo "$(tput bold)Error$(tput sgr0) $?: ${pkg}*.tar.{xz,zst} not found" fi if [ "${preserve}" != "--preserve" ]; then echo "cleaning up" rm -rf ~/tmp-${pkg} fi echo "" fi } aur "$@"