1
0
mirror of https://github.com/aquatix/dotfiles.git synced 2025-12-06 21:45:10 +01:00
Files
dotfiles/bin/update_repos
2014-07-18 11:48:59 +02:00

69 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
saveIFS="$IFS"
IFS=$'\n'
LINES=($(<~/.git_repos))
IFS="$saveIFS"
# Set defaults to user's homedir and no group (e.g., subdir)
WORKSPACE=$HOME
GRP=""
for LINE in "${LINES[@]}"; do
if [ ${LINE:0:1} = '#' ] || [ -z $LINE ]; then
# Comment or empty line encountered, skip
continue
fi
if [ ${LINE:0:1} = 'workspace=' ]; then
# TODO: strip 'workspace=' from LINE
#WORKSPACE="$HOME/workspace/projects"
WORKSPACE="$HOME/$LINE"
if [ ! -e $WORKSPACE ]; then
mkdir -p $WORKSPACE
fi
fi
if [ ${LINE:0:1} = '[' ]; then
echo 'group: $GRP'
# TODO: strip [ and ] from LINE
GRP=$LINE
fi
if [ ! -e $WORKSPACE/$GRP ]; then
mkdir $WORKSPACE/$GRP
elif [ -f $WORKSPACE/$GRP ]; then
echo -e "[\e[31mX\e[0m] Group directory already exists as file: $WORKSPACE/$GRP"
exit 1
fi
if [ -e ~/.git_group_$GRP ]; then
saveIFS="$IFS"
IFS=$'\n'
REPOS=($(<~/.git_group_$GRP))
IFS="$saveIFS"
for REPO in "${REPOS[@]}"; do
cd $WORKSPACE/$GRP
REPODIR=$(basename "$REPO")
#extension="${filename##*.}"
REPODIR="${REPODIR%.*}"
if [ -e $REPODIR ]; then
cd $REPODIR
if ! git diff --quiet; then
echo -e "[\e[31mX\e[0m] $GRP/$REPODIR changed - $WORKSPACE/$GRP/$REPODIR"
else
echo -e "[\e[32mU\e[0m] $GRP/$REPODIR"
git pull --quiet
git push --quiet
fi
else
echo -e "[\e[33mC\e[0m] $GRP/$REPODIR"
git clone --quiet $REPO
fi
done
else
echo -e "[\e[31mX\e[0m] Group config file ~/.git_group_$GRP not found"
fi
done