aboutsummaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2016-10-02 18:37:01 -0300
committerSilvio Rhatto <rhatto@riseup.net>2016-10-02 18:37:01 -0300
commit46e00518dec147c889d2d9e1a20d0dc1806ee7e6 (patch)
treeab492c791c5a81d1e47ffd1d71dcf3b7bfd0c2bc /share
parent6933ca88b0da38012239e63cd3f7ec12e7108e33 (diff)
downloadhydra-46e00518dec147c889d2d9e1a20d0dc1806ee7e6.tar.gz
hydra-46e00518dec147c889d2d9e1a20d0dc1806ee7e6.tar.bz2
Refactor sync-media
Diffstat (limited to 'share')
-rwxr-xr-xshare/hydractl/sync-media144
1 files changed, 74 insertions, 70 deletions
diff --git a/share/hydractl/sync-media b/share/hydractl/sync-media
index a4fb69a..e8f01dd 100755
--- a/share/hydractl/sync-media
+++ b/share/hydractl/sync-media
@@ -144,80 +144,63 @@ if [ ! -z "$REMOTE" ]; then
fi
fi
-# Commit changes
-if [ -d "$CACHE" ]; then
- # Fix cache permissions
- #echo "Fixing $CACHE permissions..."
- #$sudo find $CACHE -type f -exec chmod 644 {} \;
- #$sudo find $CACHE -type d -exec chmod 755 {} \;
+# Ensure cache exists
+mkdir -p $CACHE
+
+# Fix cache permissions
+#echo "Fixing $CACHE permissions..."
+#$sudo find $CACHE -type f -exec chmod 644 {} \;
+#$sudo find $CACHE -type d -exec chmod 755 {} \;
+sync_media_incoming_perms
+
+# Iterate over existing repositories in the local cache
+for folder in `ls $CACHE`; do
+ # Sync each repository in the local cache
+ if [ -d "$CACHE/$folder/.git/annex" ]; then
+ if [ "`git -C $CACHE/$folder config sync-media.skip`" == "true" ]; then
+ continue
+ fi
- sync_media_incoming_perms
+ (
+ cd $CACHE/$folder
+ echo "Syncing $CACHE/$folder..."
+
+ sync_media_playlist_perms
+ sync_media_ensure_remote $REMOTE $VOLUME/$MEDIA/$folder
+ sync_media_identity
+ sync_media_add
+ git annex sync
+ sync_media_getall $CACHE/$folder
+ sync_media_fsck
+ sync_media_dropunused
+ )
+ fi
+
+ # Ensure the removable media has each repository listed in the local cache
+ if [ ! -z "$DRIVE" ]; then
+ mkdir -p $VOLUME/$MEDIA
- # Add and update local repositories
- for folder in `ls $CACHE`; do
if [ -d "$CACHE/$folder/.git/annex" ]; then
- if [ "`git -C $CACHE/$folder config sync-media.skip`" == "true" ]; then
- continue
+ if [ ! -d "$VOLUME/$MEDIA/$folder" ]; then
+ (
+ cd $VOLUME/$MEDIA
+ echo "Initializing $VOLUME/$MEDIA/$folder..."
+ git clone $CACHE/$folder && cd $folder && sync_media_identity && git annex init $DRIVE && \
+ git remote rename origin $HOST && cd $CACHE/$folder && git remote add $DRIVE $VOLUME/$MEDIA/$folder
+ )
fi
-
- #if [ "`git -C $CACHE/$folder config sync-media.ready`" != "true" ]; then
- # echo "Skipping $CACHE/$folder: not sync-media ready, please config your repo."
- # continue
- #fi
-
- (
- cd $CACHE/$folder
- echo "Syncing $CACHE/$folder..."
-
- sync_media_playlist_perms
- sync_media_ensure_remote $REMOTE $VOLUME/$MEDIA/$folder
- sync_media_identity
- sync_media_add
- git annex sync
- sync_media_getall $CACHE/$folder
- sync_media_fsck
- sync_media_dropunused
- )
- fi
- done
-
- if [ ! -z "$DRIVE" ]; then
- if [ ! -d "$VOLUME/$MEDIA" ]; then
- echo "Folder $VOLUME/$MEDIA does not exist..."
- else
- for folder in `ls $CACHE`; do
- if [ -d "$CACHE/$folder/.git/annex" ]; then
- if [ "`git -C $CACHE/$folder config sync-media.skip`" == "true" ]; then
- continue
- fi
-
- #if [ "`git -C $CACHE/$folder config sync-media.ready`" != "true" ]; then
- # echo "Skipping $CACHE/$folder: not sync-media ready, please config your repo."
- # continue
- #fi
-
- if [ ! -d "$VOLUME/$MEDIA/$folder" ]; then
- (
- cd $VOLUME/$MEDIA
- echo "Initializing $VOLUME/$MEDIA/$folder..."
- git clone $CACHE/$folder && cd $folder && sync_media_identity && git annex init $DRIVE && \
- git remote rename origin $HOST && cd $CACHE/$folder && git remote add $DRIVE $VOLUME/$MEDIA/$folder
- )
- fi
- elif [ ! -d "$VOLUME/$MEDIA/$folder" ]; then
- if [ ! -e "$CACHE/$folder/.sync-media/skip" ]; then
- echo "Syncing $VOLUME/$MEDIA/$folder..."
- rsync -av --delete --exclude=.sync-media $CACHE/$folder/ $VOLUME/$MEDIA/$folder/
- fi
- fi
- done
+ elif [ ! -d "$VOLUME/$MEDIA/$folder" ]; then
+ mkdir -p $VOLUME/$MEDIA/$folder
fi
fi
-fi
+done
-# Retrieve changes at media volumes
+# Process removable or remote media
if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
+ # Iterate over existing repositories in the removable media
for folder in `ls $VOLUME/$MEDIA`; do
+
+ # Sync each local repository in the removable media
if [ -d "$VOLUME/$MEDIA/$folder/.git/annex" ]; then
if [ "`git -C $VOLUME/$MEDIA/$folder config sync-media.skip`" == "true" ]; then
continue
@@ -239,10 +222,31 @@ if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
#git annex drop --auto --numcopies=2
)
elif [ -d "$CACHE/$folder" ]; then
- # Avoid empty source folders or those configured to be skipped
- if [ ! -e "$CACHE/$folder/.sync-media/skip" ] && [ ! -z "`ls -1 $CACHE/$folder`" ]; then
- echo "Syncing $VOLUME/$MEDIA/$folder..."
- rsync -av --delete --exclude=.sync-media $CACHE/$folder/ $VOLUME/$MEDIA/$folder/
+ # Avoid those configured to be skipped
+ if [ ! -e "$CACHE/$folder/.sync-media/skip" ]; then
+ # Avoid empty source folders
+ if [ ! -z "`ls -1 $CACHE/$folder`" ]; then
+ echo "Syncing $CACHE/$folder into $VOLUME/$MEDIA/$folder..."
+ rsync -av --delete --exclude=.sync-media $CACHE/$folder/ $VOLUME/$MEDIA/$folder/
+ elif [ ! -z "`ls -1 $VOLUME/$MEDIA/$folder`" ]; then
+ echo "Syncing $VOLUME/$MEDIA/$folder into $CACHE/$folder..."
+ rsync -av --delete --exclude=.sync-media $VOLUME/$MEDIA/$folder/ $CACHE/$folder/
+ fi
+ fi
+ fi
+
+ # Ensure the local cache has each repository listed in the removable media
+ if [ ! -d "$CACHE/$folder" ]; then
+ if [ -d "$VOLUME/$MEDIA/$folder/.git/annex" ]; then
+ (
+ cd $CACHE
+ echo "Initializing $CACHE/$folder..."
+ git clone $VOLUME/$MEDIA/$folder && cd $folder && sync_media_identity && git annex init $HOST && \
+ git remote rename origin $REMOTE && cd $VOLUME/$MEDIA/$folder && git remote add $HOST $CACHE/$folder
+ )
+ else
+ echo "Syncing $VOLUME/$MEDIA/$folder into $CACHE/$folder..."
+ rsync -av --delete --exclude=.sync-media $VOLUME/$MEDIA/$folder/ $CACHE/$folder/
fi
fi
done
@@ -264,7 +268,7 @@ elif [ ! -z "$REMOTE" ]; then
else
# Avoid empty source folders or those configured to be skipped
if [ ! -e "$CACHE/$folder/.sync-media/skip" ] && [ ! -z "`ls -1 $CACHE/$folder`" ]; then
- echo "Syncing $VOLUME/$MEDIA/$folder..."
+ echo "Syncing $CACHE/$folder into $REMOTE.$DOMAIN:$CACHE/$folder..."
rsync -av --delete --exclude=.sync-media $CACHE/$folder/ $REMOTE.$DOMAIN:$CACHE/$folder/
fi
fi