conf-sync/conf-sync.sh

33 lines
857 B
Bash
Raw Normal View History

2022-03-13 12:18:06 +01:00
#!/usr/bin/env bash
2022-03-12 18:14:11 +01:00
source "$(dirname "$0")/variables.conf"
2022-03-13 11:40:33 +01:00
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"
2022-03-12 18:14:11 +01:00
continue
fi
2022-03-13 11:40:33 +01:00
git -C $dir fetch 2>/dev/null >/dev/null
2022-03-12 18:14:11 +01:00
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"
2022-03-13 11:40:33 +01:00
git -C $dir pull 2>/dev/null >/dev/null
if [ -e $dir/install.sh ]; then
2022-03-12 18:14:11 +01:00
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