Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created August 12, 2024 09:01
Show Gist options
  • Save pepijndevos/29c22ba80ca2d891bd855b4fe9aa7024 to your computer and use it in GitHub Desktop.
Save pepijndevos/29c22ba80ca2d891bd855b4fe9aa7024 to your computer and use it in GitHub Desktop.
Barebones AUR wrapper
#!/bin/bash
# Function to clone AUR package
clone_package() {
if [ -d ~/aur/"$1" ]; then
echo "Package '$1' already exists."
else
git clone "https://aur.archlinux.org/$1.git" ~/aur/"$1"
echo "Package '$1' cloned successfully."
fi
}
# Function to update AUR package
update_package() {
if [ -z "$1" ]; then
updated_packages=()
for package_dir in ~/aur/*/; do
package=$(basename "$package_dir")
cd "$package_dir" || exit
before_log=$(git log -1 --pretty=%H)
git pull &> /dev/null
after_log=$(git log -1 --pretty=%H)
if [ "$before_log" != "$after_log" ]; then
updated_packages+=("$package")
fi
done
if [ ${#updated_packages[@]} -eq 0 ]; then
echo "No updates available for any packages."
else
echo "Updated packages:"
printf '%s\n' "${updated_packages[@]}"
fi
else
if [ -d ~/aur/"$1" ]; then
cd ~/aur/"$1" || exit
before_log=$(git log -1 --pretty=%H)
git pull &> /dev/null
after_log=$(git log -1 --pretty=%H)
if [ "$before_log" != "$after_log" ]; then
echo "Package '$1' updated successfully."
else
echo "No updates available for package '$1'."
fi
else
echo "Package '$1' does not exist. Use 'clone' action to clone it first."
fi
fi
}
# Function to build AUR package
build_package() {
if [ -d ~/aur/"$1" ]; then
cd ~/aur/"$1" || exit
makepkg -si
else
echo "Package '$1' does not exist. Use 'clone' action to clone it first."
fi
}
# Function to install AUR package
install_package() {
if [ -f ~/aur/"$1"/*.pkg.tar.zst ]; then
sudo pacman -U ~/aur/"$1"/*.pkg.tar.zst
else
echo "Package '$1' is not built yet. Use 'build' action to build it first."
fi
}
# Main script
case "$1" in
clone)
clone_package "$2"
;;
update)
update_package "$2"
;;
build)
build_package "$2"
;;
install)
install_package "$2"
;;
*)
echo "Usage: aur.sh [clone|update|build|install] package_name"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment