]> gitweb.fluxo.info Git - hydra.git/commitdiff
Feat: hydractl: sync-media: rsync support from non-empty to empty folders
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 30 Sep 2023 22:24:41 +0000 (19:24 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 30 Sep 2023 22:24:41 +0000 (19:24 -0300)
share/hydractl/sync-media

index 69c4ed32680f80c3ab1927c362c8db5dd7f5a3c7..d463e443fbe311de2017445b10509a7fddfc2915 100755 (executable)
@@ -265,20 +265,39 @@ if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
       # Avoid those configured to be skipped
       if [ ! -e "$CACHE/$folder/.sync-media/skip" ]; then
         echo "Syncing $CACHE/$folder with $VOLUME/$MEDIA/$folder..."
-        unison $CACHE/$folder $VOLUME/$MEDIA/$folder -auto -logfile /dev/null
-
-        # 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
+
+        if [ -e "$CACHE/$folder/.sync-media/method" ]; then
+          method="`cat $CACHE/$folder/.sync-media/method`"
+        else
+          method="unison"
+        fi
+
+        if [ "$method" == "unison" ];
+          unison $CACHE/$folder $VOLUME/$MEDIA/$folder -auto -logfile /dev/null
+        elif [ "$method" == "rsync" ]; then
+          # Ensure both endpoint folders exist
+          mkdir -p $CACHE/folder
+          mkdir -p $VOLUME/$MEDIA/$folder
+
+          # One way rsync method, from the non-empty to the empty folder
+          if [ ! -z "`ls -1 $CACHE/$folder`" ] && [ -z "`ls -1 $VOLUME/$MEDIA/$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`" ] && [ -z "`ls $CACHE/$folder`" ]; then
+            echo "Syncing $VOLUME/$MEDIA/$folder into $CACHE/$folder..."
+            rsync -av --delete --exclude=.sync-media $VOLUME/$MEDIA/$folder/ $CACHE/$folder/
+          else
+            echo "Skipping rsyncing between $CACHE/$folder and $VOLUME/$MEDIA/$folder since both are non-empty"
+          fi
+        elif [ "$method" == "" ]; then
+          true
+        else
+          echo "Skipping unknown sync method $method"
+        fi
       fi
     fi
 
-    # Run a custom synchronizer
+    # Run an additional custom synchronizer
     if [ -x "$CACHE/$folder/.sync-media/custom" ]; then
       $CACHE/$folder/.sync-media/custom $VOLUME/$MEDIA/$folder
     fi