conf-sync/conf-sync.sh

37 lines
943 B
Bash
Executable File

#!/usr/bin/env bash
source "$(dirname "$0")/variables.conf"
for dir in $sync_directory/*; do
git -C $dir rev-parse 2>/dev/null >/dev/null
if [ "$?" -ne 0 ]; then
echo "$dir: not a Git repo"
continue
fi
if [ -f $dir/.disabled ]; then
echo "$dir update is disabled."
continue
fi
git -C $dir fetch 2>/dev/null >/dev/null
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git -C $dir rev-parse @)
REMOTE=$(git -C $dir rev-parse "$UPSTREAM")
BASE=$(git -C $dir merge-base @ "$UPSTREAM")
if [ $LOCAL = $REMOTE ]; then
echo "$dir: up-to-date"
elif [ $LOCAL = $BASE ]; then
echo "pulling $dir"
git -C $dir pull 2>/dev/null >/dev/null
if [ -e $dir/install.sh ]; then
echo "Running $dir's install script..."
$dir/install.sh
fi
elif [ $REMOTE = $BASE ]; then
echo "WARNING: $dir is ahead of remote!"
else
echo "WARNING: $dir and remote have diverged!"
fi
done
exit 0