Wednesday, May 27, 2015

Update all GIT and SVN repositories in all subfolders

If you happen to have a large collection of tools, some of which come from GitHub or other Git repositories, some others come from Google code or other subversion repos, this is for you.

The script below will recursively scan a base directory and find all Git and SVN repos, and update them.

Add a crontab entry to call this script every day if you like.

#!/bin/bash

BASEDIR=${HOME}/pentest

# Updating git repos
for d in `find ${BASEDIR} -type d -exec test -d '{}/.git' \; -prune -print`; do
   cd "$d"
   echo Updating `pwd` ...
   git pull
done

# Updating SVN repos
for d in `find ${BASEDIR} -type d -exec test -d '{}/.svn' \; -prune -print`; do
   cd "$d"
   echo Updating `pwd` ...
   svn up
done

That's all.