summaryrefslogtreecommitdiff
path: root/share/hydractl/sync-media-export
blob: 8647acc1882a0af55c3b11b6899b3bd4e35d98ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#
# Copy git-annex repositories to remote destination.
#

# Parameters
BASENAME="`basename $0`"
DESTINATION="$1"
DOMAIN="`facter DOMAIN`"
MEDIA="/var/cache/media"

# Syntax check
if [ -z "$DESTINATION" ]; then
  echo "usage: $BASENAME <DESTINATION>"
  exit 1
fi

# Process each repository
for file in `ls $MEDIA`; do
  if [ -d "$MEDIA/$file/.git/annex" ]; then
    (
    echo Processing "$MEDIA/$file..."

    cd $MEDIA

    # Check for remote or local destinations
    if [ ! -d "$DESTINATION" ]; then
      if ssh $DESTINATION if [ -d \"/var/cache/media/$file\" ] \; then echo exists\; fi | grep -q exists; then
        echo "Remote $file already exists, skipping..."
        continue;
      fi

      git clone $file $file.git && \
      rsync -avz $file.git/ $DESTINATION:/var/cache/media/$file/ && \
      rm -rf $file.git
      echo ""
    else
      mkdir -p $DESTINATION/var/cache/media
      if [ ! -d "$DESTINATION/var/cache/media/$FILE" ]; then
        ( cd $DESTINATION/var/cache/media && git clone $MEDIA/$file )
      fi
    fi
    )
  fi
done