diff options
Diffstat (limited to 'share/hydractl/sync-media-remotes')
-rwxr-xr-x | share/hydractl/sync-media-remotes | 51 |
1 files changed, 51 insertions, 0 deletions
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 <dest>" + 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 |