diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2023-09-30 19:24:41 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2023-09-30 19:24:41 -0300 |
commit | 985de3e83c2af6d08c78d98045130984302ba7dc (patch) | |
tree | 818c76a4d4c3e1108047c7db3a458b7be0532a27 | |
parent | 42b13d0d61555abe706b1b48f4ece23965a2e308 (diff) | |
download | hydra-985de3e83c2af6d08c78d98045130984302ba7dc.tar.gz hydra-985de3e83c2af6d08c78d98045130984302ba7dc.tar.bz2 |
Feat: hydractl: sync-media: rsync support from non-empty to empty folders
-rwxr-xr-x | share/hydractl/sync-media | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/share/hydractl/sync-media b/share/hydractl/sync-media index 69c4ed3..d463e44 100755 --- a/share/hydractl/sync-media +++ b/share/hydractl/sync-media @@ -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 |