Add script to sync all repositories

This commit is contained in:
Martchus 2023-06-09 17:22:46 +02:00
parent 6be974109d
commit 22286b8d46
1 changed files with 41 additions and 0 deletions

41
sync-all.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
set -e
subdirs_path=$(dirname -- "$(realpath -- "$0")")
cd "$subdirs_path"
declare -A repo_names=(
[c++utilities]=cpp-utilities
[qtutilities]=
[qtforkawesome]=
[syncthingtray]=
[tagparser]=
[tageditor]=
[passwordfile]=
[passwordmanager]=
[videodownloader]=
[reflective-rapidjson]=
[dbus-soundrecorder]=
[geocoordinatecalculator]=
)
# ensure a clone of all repositories exists
for dir in "${!repo_names[@]}"; do
[[ -d ../$dir/.git ]] && continue
echo "==> Cloning $dir"
repo=${repo_names[$dir]:-$dir}
git -C .. clone "git@github.com:Martchus/$repo.git" "$dir"
done
# ensure all repositories are up-to-date
for dir in ../* ; do
[[ -d $dir/.git ]] || continue
echo "==> Updating $dir"
git -C "$dir" remote update
branch_name=$(git -C "$dir" symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-DETACHED}
if output=$(git -C "$dir" status --porcelain) && [[ -z $output ]] && [[ $branch_name == DETACHED || $branch_name == master ]]; then
git -C "$dir" reset --hard origin/master
fi
done