summaryrefslogtreecommitdiff
path: root/share/hydractl/sync-media-initremotes
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2016-10-02 15:31:42 -0300
committerSilvio Rhatto <rhatto@riseup.net>2016-10-02 15:31:42 -0300
commitfdb07b542860089eb208ec5967826a2225899d10 (patch)
tree1684d5eee1520e8416c6775416f459afed04c02b /share/hydractl/sync-media-initremotes
parentd13a337e8bc54ace1ea98ff5faae01d525d9dd21 (diff)
downloadhydra-fdb07b542860089eb208ec5967826a2225899d10.tar.gz
hydra-fdb07b542860089eb208ec5967826a2225899d10.tar.bz2
Adds media and backup scripts originally from puppet-backup
Diffstat (limited to 'share/hydractl/sync-media-initremotes')
-rwxr-xr-xshare/hydractl/sync-media-initremotes92
1 files changed, 92 insertions, 0 deletions
diff --git a/share/hydractl/sync-media-initremotes b/share/hydractl/sync-media-initremotes
new file mode 100755
index 0000000..839deea
--- /dev/null
+++ b/share/hydractl/sync-media-initremotes
@@ -0,0 +1,92 @@
+#!/bin/bash
+#
+# Add git-annex remotes to repository in removable media or local cache.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+VOLUME="$1"
+TYPES="$2"
+DOMAIN="`facter DOMAIN`"
+HOST="`facter hostname`"
+CACHES=""
+VOLUMES=""
+BOXES=""
+
+# Fix identity
+function sync_media_identity {
+ if [ -z "`git config --local user.email`" ] || [ -z "`git config --local user.name`" ]; then
+ repo="$(basename `pwd`)"
+ git config user.name "${repo^} Archive"
+ git config user.email "$repo@localhost"
+ fi
+}
+
+# Syntax check
+if [ -z "$VOLUME" ]; then
+ echo "usage: $BASENAME <volume> [<caches|volumes|boxes> [remotes]]"
+ exit 1
+fi
+
+# Determine media folder
+if [ "$VOLUME" == "$HOST" ] || [ "$VOLUME" == "localhost" ]; then
+ MEDIA="/var/cache/media"
+else
+ MEDIA="/media/$VOLUME/media.$DOMAIN"
+fi
+
+# Determine remote type
+shift 2
+if [ "$TYPES" == 'caches' ]; then
+ # Remotes are caches of local boxes
+ CACHES="$*"
+elif [ "$TYPES" == 'volumes' ]; then
+ # Remotes are removable media
+ VOLUMES="$*"
+elif [ "$TYPES" == 'boxes' ]; then
+ # Remotes are remote boxes
+ BOXES="$*"
+fi
+
+# Process each repository
+for file in `ls $MEDIA`; do
+ if [ -d "$MEDIA/$file/.git" ]; then
+ (
+ echo Processing "$MEDIA/$file..."
+ cd $MEDIA/$file
+ sync_media_identity
+
+ if git remote | grep -q "^origin$"; then
+ echo "Removing origin..."
+ git remote rm origin
+ fi
+
+ if [ ! -d "$MEDIA/$file/.git/annex" ]; then
+ git annex init $VOLUME
+ fi
+
+ for remote in $CACHES; do
+ echo "Adding /var/cache/$remote/media/$file remote..."
+ git remote add $remote /var/cache/$remote/media/$file
+ done
+
+ for remote in $VOLUMES; do
+ echo "Adding /media/$remote/media.$DOMAIN/$file..."
+ git remote add $remote /media/$remote/media.$DOMAIN/$file
+ done
+
+ for remote in $BOXES; do
+ if ! echo $remote | grep -q '\.'; then
+ host="$remote.$DOMAIN"
+ else
+ host="$remote"
+ fi
+
+ echo "Adding ssh://$host/var/cache/media/$file..."
+ git remote add $remote ssh://$host/var/cache/media/$file
+ done
+
+ echo ""
+ )
+ fi
+done