Skip to content

Instantly share code, notes, and snippets.

@barraIhsan
Created December 4, 2024 04:13
Show Gist options
  • Save barraIhsan/f980911f441135aa40aa67ddbdf747bd to your computer and use it in GitHub Desktop.
Save barraIhsan/f980911f441135aa40aa67ddbdf747bd to your computer and use it in GitHub Desktop.
Install AUR Helper
# ansi
GREEN='\033[0;32m'
RED='\033[0;31m'
RESET='\033[0m'
# exit if paru or yay is installed
if command -v paru &>/dev/null; then
echo -e "${GREEN}paru${RESET} is already installed."
exit
elif command -v yay &>/dev/null; then
echo -e "${GREEN}yay${RESET} is already installed."
exit
fi
echo -e "${RED}Neither${RESET} ${GREEN}paru${RESET} ${RED}nor${RESET} ${GREEN}yay${RESET} are installed."
# ask aur helper
while true; do
echo -ne "Which ${GREEN}AUR helper${RESET} do you want to install? (yay/paru): "
read aurhelper
# check if the input is valid
if [ "$aurhelper" = "yay" ] || [ "$aurhelper" = "paru" ]; then
break
else
echo -e "${RED}Invalid choice.${RESET} Please enter '${GREEN}yay${RESET}' or '${GREEN}paru${RESET}'."
fi
done
# check for git
if ! command -v git &>/dev/null; then
# install git if it's not installed yet
echo -e "${GREEN}git${RESET} is ${RED}not installed.${RESET} Installing ${GREEN}git${RESET}..."
sudo pacman -S git
echo -e "${GREEN}git${RESET} has been installed!"
fi
# start installing aurhelper
echo -e "Installing ${GREEN}${aurhelper}${RESET}..."
git clone https://aur.archlinux.org/${aurhelper}.git /tmp/${aurhelper}
cd /tmp/${aurhelper}
# build and install the aurhelper
# show informative error if fail
makepkg -si || {
echo -e "${RED}Failed to build and install${RESET} ${GREEN}${aurhelper}${RESET}!"
exit 1
}
echo -e "${GREEN}${aurhelper}${RESET} has been installed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment