Skip to content

Instantly share code, notes, and snippets.

@yash1610
Last active March 11, 2016 06:24
Show Gist options
  • Save yash1610/eb15379dfcbce746050b to your computer and use it in GitHub Desktop.
Save yash1610/eb15379dfcbce746050b to your computer and use it in GitHub Desktop.
Bash script to auto update installed aur packages
#!/bin/bash
green='\E[32m'
bold='\033[1m'
normal='\033[0m'
#Create a directory and cd into it
echo -e "\n$bold$green"Creating a temp directory to work in..."$normal\n"
TEMPDIR=$(mktemp -d)
pushd $TEMPDIR
echo -e "\n$bold$green"Working in $TEMPDIR"$normal\n"
#Update Checker
echo -e "\n$bold$green"Checking packages that need to be updated"$normal\n"
for i in $(pacman -Qqm); do
if [ "$(vercmp $(pacman -Q $i | cut -d" " -f2) $(curl "https://aur.archlinux.org/rpc/?v=5&type=info&arg\[\]=$i" | jshon -e results -a -e Version -u))" != 0 ]; then
echo $i >> update.txt
fi
done
#Downlaod script
echo -e "\n$bold$green"Downloading AUR packages"$normal\n"
while read pkg; do
curl -L -O https://aur.archlinux.org/cgit/aur.git/snapshot/$pkg.tar.gz
done <update.txt
#Extraction script
echo -e "\n$bold$green"Extracting AUR packages into $TEMPDIR"$normal\n"
for i in $(echo *.tar.gz); do
tar -xvf $i
done
rm ./*.tar.gz
#Build script
echo -e "\n$bold$green"Building AUR packages"$normal\n"
for dir in $TEMPDIR/*; do
cd "$dir" && echo -e "\n$bold$green"$dir"$normal\n" && makepkg -sr
done
cd ..
#Install Script
echo -e "\n$bold$green"Installing AUR packages"$normal\n"
find . -name '*.pkg.tar.xz' -exec sudo pacman -U {} +;
#Clean-up script
echo -e "\n$bold$green"Removing $TEMPDIR"$normal\n"
popd
rm -rf $TEMPDIR
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment