I am working with a bigger number of different version control systems. I use these from different locations, so I have the use-case of frequently updating those repositories.
The following script recursively traverses a directory structure; once it finds a repository of a “known”version control system it updates that repository and continues to go on in the directory structure. Additionally, it colors the output depending on the result. Furthermore, it is possible to skip certain directories by placing a file named “.skip” in a respective directory.
#!/bin/sh
#
# Copyright 2012, Ruediger Gad <r.c.g@gmx.de>
#
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/
# or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
#
# Usage:
# Update all repositories from the current path on: update_repositories.sh
# Update all repositories within a given path: update_repositories.sh <PATH>
#
if [ $# -eq 0 ]
then
START_DIR="$(pwd)"
else
START_DIR="$1"
fi
function colorize_output(){
OUTPUT=$("$@")
if [ $? -eq 0 ]
then
echo -e "\E[42m$OUTPUT\E[0m"
else
echo -e "\E[41m$OUTPUT\E[0m"
fi
}
function process_directory(){
for i in "$1"/*
do
if [ -d "$i" ]
then
echo "Processing \"$i\"..."
if [ -e "$i"/.skip ]
then
echo -e "\E[43mSkipping \"$i\"...\E[0m"
elif [ -d "$i"/.svn ]
then
cd "$i"
colorize_output svn up
cd - &> /dev/null
elif [ -d "$i"/.git ]
then
cd "$i"
colorize_output git pull
cd - &> /dev/null
elif [ -s "$i"/.osc ]
then
cd "$i"
colorize_output osc up
cd - &> /dev/null
else
process_directory "$i"
fi
fi
done
}
process_directory "$START_DIR"
Pingback: Automatically clone all repositories defined in conf/gitolite.conf | ruedigergad