From 2d3a2cd3d01e43c6e3c1a6eebad26bdf2a422d5a Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 8 Nov 2016 15:06:43 -0200 Subject: Initial logic for a sync-media-remotes --- share/hydractl/sync-media-remotes | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 share/hydractl/sync-media-remotes (limited to 'share/hydractl/sync-media-remotes') diff --git a/share/hydractl/sync-media-remotes b/share/hydractl/sync-media-remotes new file mode 100755 index 0000000..fd69708 --- /dev/null +++ b/share/hydractl/sync-media-remotes @@ -0,0 +1,51 @@ +#!/bin/bash +# +# Keep git remotes in sync among media archives. +# + +# Parameters +BASENAME="$0" +DEST="$1" +MEDIA="/var/cache/media" + +# Syntax +if [ -z "$DEST" ]; then + echo "usage: $BASENAME " + exit 1 +elif [ ! -d "$DEST/$MEDIA" ]; then + echo "folder $DEST/$MEDIA does not exist." + exit 1 +fi + +# TODO +echo "Needs work!" +exit + +# Run +for folder in `ls $MEDIA`; do + if [ -d "$DEST/$MEDIA/$folder/.git" ]; then + git -C $MEDIA/$folder remote -v | grep "(fetch)" | sed -e 's/(fetch)//' | while read remote; do + ( + cd $DEST/$MEDIA/$folder + name="`echo $remote | cut -d ' ' -f 1`" + url="`echo $remote | cut -d ' ' -f 2`" + + # Add and update + if [ "$name" != "all" ]; then + if ! git remote | grep -q "^$name$" ]; then + git remote add $remote + else + oldurl="`git remote -v | grep "^$name$" | grep "(fetch)" | cut -d ' ' -f 2`" + + if [ "$url" != "$oldurl" ]; then + git remote set-url $name --delete $oldurl + git remote set-url $name --add $url + fi + fi + fi + + # Remove dangling remotes + ) + done + fi +done -- cgit v1.2.3