Skip to content

Instantly share code, notes, and snippets.

@ewancg
Last active May 26, 2023 17:43
Show Gist options
  • Save ewancg/f51336b92f6d69d3becb7d552aee95b8 to your computer and use it in GitHub Desktop.
Save ewancg/f51336b92f6d69d3becb7d552aee95b8 to your computer and use it in GitHub Desktop.
Simple AUR helper for Arch Linux
#!/usr/bin/env bash
# AUR helper, similar to that of paru or yay, but far simpler and written in bash.
# This is better for a few reasons:
# - No pacman-esque syntax (-S)
# This is unneeded as pacman can handle all except for installation of AUR
# packages, such as sync, query, etc.
# - No compile-time dependencies (rather, no compilation at all)
# Paru and yay require Rust and Golang respectively -- requiring hundreds of MiB
# of code to be installed and immediately deleted once the helper package is built.
# Update 2/16/22: Add --noconfirm to makepkg invocation
# Update 5/26/23: Move shebang to line 1 (thanks ChillerDragon)
# Print syntax when no arguments are provided / --help is given
function help {
printf "Syntax:\n aur [arg1], [arg2]... - Download packages\n aur --help - Show this page\n"
exit
}
# Ensure user & their environment meet the necessary conditions for package installation
function check {
# If user doesn't have write priviliges:
if [ ! -w `pwd` ]
then
printf "You do not have write privilages.\n"
exit
fi
# If package's interim path already exists in the form of a non-empty file or directory:
if [ -s ./$1 ]
then
printf "Destination path already exists and is not empty.\n"
exit
fi
# If user ran the script as root:
if [ "$EUID" -eq 0 ]
then
printf "makepkg cannot be run as root.\n"
exit
fi
}
# Install package -- main component
function install {
git clone https://aur.archlinux.org/$1
cd ./$1
makepkg -cirs --noconfirm
}
# Clean up environment if cancelled at any stage during installation (also runs after installation)
function cleanup {
printf "makepkg finished. Removing build directory...\n"
# If the working directory is equal to the current argument (i.e. they are in the package's folder)
if [ `basename $(pwd)` = $1 ]
then
cd ../
rm -rdf ./$1
# If the working directory is not the package's folder (i.e. script is manually aborted before install function is run)
else [ -d ./$1 ]
rm -rdf ./$1
fi
}
# Shoehorn a newline in between the probable output character of SIGINT and the following contents
function interrupt {
printf "\n"
cleanup $1
}
# Trap SIGINT so that the script can clean up before exiting
trap "interrupt $1" INT
# Check if first argument is empty (essentially the same as "if [ $# -eq 0 ]")
if [ -z $1 ]
then
printf "Package parameter cannot be empty.\n"
help
fi
# Check if any of the arguments are equal to "--help"
for var in "$@"
do
if [ $var = "--help" ]
then
help
fi
done
# Iterate script on a per-argument basis for multiple packages
for var in "$@"
do
check $var
install $var
cleanup $var
done
# This is a quick & dirty adaptation of a bash function I wrote for my personal use. Please inform me of anything that's not ideal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment