Skip to content

Instantly share code, notes, and snippets.

@Xananax
Last active February 24, 2020 05:20
Show Gist options
  • Save Xananax/62e662580325b0da5031a9067dd25a72 to your computer and use it in GitHub Desktop.
Save Xananax/62e662580325b0da5031a9067dd25a72 to your computer and use it in GitHub Desktop.
Update all AUR repos
# vi:syntax=sh
#!/usr/bin/env bash
# AUR updated
# Checks all directories for updates, then
# runs makepkg -si for each updated git repo
checkIfRepo(){
stat "$1" > /dev/null || return 1;
cd $1; echo "Checking $1"
git status --porcelain >/dev/null && cd .. || return 1; # A fatal error if $PWD is not a git repos
}
updateRepo() {
local dir="$1"
cd $dir # switch to the git repo
git checkout master >/dev/null 2>&1
git remote update -p >/dev/null
reslog=$(git log HEAD..origin/master --oneline)
if [[ "${reslog}" != "" ]] ; then
echo "$dir" needs updating
git merge --ff-only origin/master
cd ..
return 0
else
cd ..
return 1
fi
}
update() {
local dir="$1"
cd $dir && makepkg -si --needed
cd ..
}
update_all() {
for thing in "$@"; do
update $thing
done;
}
usage(){
echo "arch updater"
echo "usage:"
echo "run it in the directory containing all your things"
echo "assumes all your aur stuff is in a single directory"
}
directory_to_update=${1}
if [ -z "$directory_to_update" ] ; then
echo "no directory passed in, using current directory"
directory_to_update=$PWD
fi
echo "Updating git repo's in directory: $directory_to_update"
need_update=""
for dir in $(ls $directory_to_update); do
if [ -d "${dir}" ] ; then
if checkIfRepo $dir ; then
if updateRepo $dir ; then
need_update="${need_update} $dir"
fi
fi
fi
done
echo "=================================="
echo "need updating:"
echo $need_update | tr " " "\n"
if [ -z "$need_update" ] ; then
echo "nothing to do"
else
update_all "$need_update"
echo "all done!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment