aboutsummaryrefslogtreecommitdiff
path: root/files/sync-media-init
blob: 035da0242aee3b8b0f8460b92ac9e4c6261453eb (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
46
47
48
49
#!/bin/bash
#
# Add git-annex remotes to repository in removable media or local cache.
#

# Parameters
BASENAME="`basename $0`"
VOLUME="$1"
DOMAIN="`facter DOMAIN`"
#REMOTE_BOXES=""
#REMOTE_VOLUMES=""

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

# Determine media folder
if [ "$VOLUME" == "`facter hostname`" ]; then
  MEDIA="/var/cache/media"
else
  MEDIA="/media/$VOLUME/media.$DOMAIN"
fi

# Process each repository
for file in `ls $MEDIA`; do
  if [ -d "$MEDIA/$file/.git/annex" ]; then
    (
    echo Processing "$MEDIA/$file..."
    cd $MEDIA/$file
    echo "Removing origin..."
    git remote rm origin
    git annex init $VOLUME

    for remote in $REMOTE_BOXES; do
      echo "Adding /var/cache/$remote/media/$file remote..."
      git remote add $remote /var/cache/$remote/media/$file
    done

    for remote in $REMOTE_VOLUMES; do
      echo "Adding /media/$remote/media.$DOMAIN/$file..."
      git remote add $remote /media/$remote/media.$DOMAIN/$file
    done

    echo ""
    )
  fi
done