#!/bin/bash if [[ $EUID -eq 0 ]]; then echo "This script must NOT be run as root, it will call sudo itself" exit 1 fi if [[ $# -ne 1 ]]; then echo "Usage: "$(basename $0)" aur_package_dir" echo echo "This is a stupid and simple AUR package upgrader" echo echo "When passed a directory where clones of AUR repositories are, this script" echo "will iterate over them directory by directory and if any contains" echo "a PKGBUILD file with pkgbase/pkgname will see if this package is installed." echo "If it is will perform git reset --hard + git pull, check for pkgver/pkgrel" echo "against what is installed and call \`makepkg --noconfirm --needed -sri\`" echo "in case they differ" exit 1 fi # From https://gist.github.com/cowboy/3118588 prevent_asking_sudo_password() { # Might as well ask for password up-front, right? sudo -v # Keep-alive: update existing sudo time stamp if set, otherwise do nothing. while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & } prevent_asking_sudo_password pushd $1 > /dev/null for dir in */; do pushd $dir > /dev/null if [ -f PKGBUILD ]; then pkgbase=$(grep -m 1 pkgbase PKGBUILD | cut -d '=' -f 2) pkgname=$(grep -m 1 pkgname PKGBUILD | cut -d '=' -f 2) # If we have a base package, check for it, using makepkg -sri anyway to install everything if [ ! -z $pkgbase ]; then pkgname=$pkgbase fi # In split packages "If pkgbase is not specified, the first element in the pkgname array is used." # (c) https://wiki.archlinux.org/index.php/PKGBUILD#Package_name # so get the first element of an array if needed if echo $pkgname | grep "^("; then pkgname=`echo $pkgname | cut -d ' ' -f 1` pkgname=${pkgname:2} fi if [ ! -z "$pkgname" ]; then pkg_info=$(pacman -Qi $pkgname 2>&1) if [ $? -eq 0 ]; then inst_version=`echo "$pkg_info" | grep -m 1 Version | sed s'/Version ://g' | xargs` if echo $inst_version | grep ':'; then inst_version=`echo $inst_version | rev | cut -d ':' -f 1 | rev` fi echo "--- Found installed package "$pkgname" version: "$inst_version rm -f *.tar.gz rm -f *.tar.xz rm -f *.tar.bz rm -f *.tar.bz2 rm -f *.zip rm -f *.deb git reset --hard git pull pkgver=$(grep -m 1 pkgver PKGBUILD | cut -d '=' -f 2 | xargs) pkgrel=$(grep -m 1 pkgrel PKGBUILD | cut -d '=' -f 2 | xargs) git_version=${pkgver}"-"${pkgrel} echo "------ Git version of this package is "$git_version if [ "$inst_version" != "$git_version" ]; then echo "--------- Package "$pkgname" installed version "$inst_version" has git version "$git_version", will reinstall if needeii # First clean everything to make sure there are patch or otjer issues makepkg -c # --noconfirm added to avoid answering 'Y' to a qestion "Do you really want to install blah blah" # --needed added because *-git packages change pkgver in PKGBUILD before installing # so it will always differ from the one in original PKGBUILD and package will be reinstalled # even if there is no point in doing it makepkg --noconfirm --needed -sric fi fi fi fi popd > /dev/null done popd > /dev/null