Facebook
From me, 5 Years ago, written in Bash.
Embed
Download Paste or View Raw
Hits: 207
  1. #!/bin/bash
  2.  
  3. if [ "$#" -ne 1 ]; then
  4.     echo "Usage: "$(basename $0)" aur_package_dir"
  5.     echo
  6.     echo "This simple script when passed a directory where clones of AUR repositories are"
  7.     echo "will iterate over then directory by directory and if any of them contains"
  8.     echo "a PKGBUILD file then with pkgname will see if this package is installed"
  9.     echo "and if it is will perform git reset --hard + git pull, check for pkgver/pkgrel"
  10.     echo "against what is installedand call makepkg -sri in case they differ"
  11.     exit 1
  12. fi
  13.  
  14. pushd $1 > /dev/null
  15.  
  16. for dir in */; do    
  17.     pushd $dir > /dev/null
  18.  
  19.     if [ -f PKGBUILD ]; then
  20.         pkgbase=$(grep -m 1 pkgbase PKGBUILD | cut -d '=' -f 2)
  21.         pkgname=$(grep -m 1 pkgname PKGBUILD | cut -d '=' -f 2)
  22.  
  23.         if [ ! -z "$pkgname" ]; then
  24.             pkg_info=$(pacman -Qi $pkgname 2>&1)
  25.             if [ $? -eq 0 ]; then
  26.                 installed_version=`echo "$pkg_info" | grep -m 1 Version | sed s'/Version         ://g' | xargs`
  27.                 echo "----- Found installed package "$pkgname" version: "$installed_version
  28.                 git reset --hard
  29.                 git pull
  30.                 pkgver=$(grep -m 1 pkgver PKGBUILD | cut -d '=' -f 2 | xargs)
  31.                 pkgrel=$(grep -m 1 pkgrel PKGBUILD | cut -d '=' -f 2 | xargs)
  32.                 git_version="${pkgver}-${pkgrel}"
  33.                 echo "----- Git version of this package is "$git_version
  34.                 if [ "$installed_version" != "$git_ver" ]; then
  35.                     echo "----- Package "$pkgname" version: "$installed_version" has git version: "$git_version" will reinstall"
  36.                     makepkg -sri
  37.                 fi
  38.             fi
  39.         fi
  40.     fi
  41.    
  42.     popd > /dev/null
  43. done
  44.  
  45. popd > /dev/null