Guest User

stupid script for updating AUR packages

a guest
Jan 18th, 2020
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.70 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ "$#" -ne 1 ]; then
  4.     echo "Usage: "$(basename $0)" aur_package_dir"
  5.     echo
  6.     echo "This is a stupid and simple AUR package upgrader"
  7.     echo
  8.     echo "When passed a directory where clones of AUR repositories are this script"
  9.     echo "will iterate over them directory by directory and if any contains"
  10.     echo "a PKGBUILD file with pkgbase/pkgname will see if this package is installed."
  11.     echo "If it is will perform git reset --hard + git pull, check for pkgver/pkgrel"
  12.     echo "against what is installed and call makepkg -sri in case they differ"
  13.     echo
  14.     echo 'Unfortunately you still have to type your sudo password when installing'
  15.     echo 'packages and I still do not know how to workaround this'a
  16.     exit 1
  17. fi
  18.  
  19. pushd $1 > /dev/null
  20.  
  21. for dir in */; do    
  22.     pushd $dir > /dev/null
  23.  
  24.     if [ -f PKGBUILD ]; then
  25.         pkgbase=$(grep -m 1 pkgbase PKGBUILD | cut -d '=' -f 2)
  26.         pkgname=$(grep -m 1 pkgname PKGBUILD | cut -d '=' -f 2)
  27.  
  28.         # If we have a base package, check for it, using makepkg -sri anyway to install everything
  29.         if [ ! -z $pkgbase ]; then
  30.             pkgname=$pkgbase
  31.         fi
  32.  
  33.         # In split packages "If pkgbase is not specified, the first element in the pkgname array is used."
  34.         # (c) https://wiki.archlinux.org/index.php/PKGBUILD#Package_name
  35.         # so get the first element of an array if needed
  36.         if echo $pkgname | grep "^("; then
  37.             pkgname=`echo $pkgname | cut -d ' '  -f 1`
  38.             pkgname=${pkgname:2}
  39.         fi
  40.  
  41.         if [ ! -z "$pkgname" ]; then
  42.             pkg_info=$(pacman -Qi $pkgname 2>&1)
  43.             if [ $? -eq 0 ]; then
  44.                 inst_version=`echo "$pkg_info" | grep -m 1 Version | sed s'/Version         ://g' | xargs`
  45.                 if echo $inst_version | grep ':'; then
  46.                     inst_version=`echo $inst_version | rev | cut -d ':' -f 1 | rev`
  47.                 fi
  48.                 echo "--- Found installed package "$pkgname" version: "$inst_version
  49.  
  50.                 git reset --hard
  51.                 git pull
  52.  
  53.                 pkgver=$(grep -m 1 pkgver PKGBUILD | cut -d '=' -f 2 | xargs)
  54.                 pkgrel=$(grep -m 1 pkgrel PKGBUILD | cut -d '=' -f 2 | xargs)
  55.                 git_version=${pkgver}"-"${pkgrel}
  56.                 echo "------ Git version of this package is "$git_version
  57.  
  58.                 if [ "$inst_version" != "$git_version" ]; then
  59.                     echo "--------- Package "$pkgname" installed version "$inst_version" has git version "$git_version", will reinstall"
  60.                     makepkg --noconfirm -sri
  61.                 fi
  62.             fi
  63.         fi
  64.     fi
  65.    
  66.     popd > /dev/null
  67. done
  68.  
  69. popd > /dev/null
Advertisement
Add Comment
Please, Sign In to add comment