-
-
Save QWxleA/cbbec2e7213a9afaebfa8f38cd0f0f05 to your computer and use it in GitHub Desktop.
Update all AUR repos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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