]> gitweb.fluxo.info Git - hydra.git/commitdiff
Feat: hydractl: sync-media: support for specifying a repository in the command line
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 1 Oct 2023 18:18:26 +0000 (15:18 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 1 Oct 2023 18:18:26 +0000 (15:18 -0300)
share/hydractl/sync-media

index 09f723956b3e85f6155ef4440701d5f778deb3f0..64861982dddae4dd3e98eb05c65d27e5dcc0b349 100755 (executable)
@@ -9,6 +9,7 @@ hydra_config_load
 
 # Parameters
 REMOTE="$1"
+REPOSITORY="$2"
 VOLUME="/media/$REMOTE"
 DOMAIN="`facter domain`"
 HOST="`facter hostname`"
@@ -182,8 +183,15 @@ $sudo chown $WHOAMI. $CACHE
 $sudo chown $WHOAMI. $CACHE/*
 sync_media_incoming_perms
 
+# Check if a specific repository was passed via the command line
+if [ -z "$REPOSITORY" ] && [ -d "$CACHE/$REPOSITORY" ] && ! echo "$REPOSITORY" | grep -q '--'; then
+  REPOSITORIES="$REPOSITORY"
+else
+  REPOSITORIES="`ls $CACHE`"
+fi
+
 # Iterate over existing repositories in the local cache
-for folder in `ls $CACHE`; do
+for folder in $REPOSITORIES; 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
@@ -237,8 +245,15 @@ done
 
 # Process removable or remote media
 if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
+  # Check if a specific repository was passed via the command line
+  if [ -z "$REPOSITORY" ] && [ -d "$VOLUME/$MEDIA/$REPOSITORY" ] && ! echo "$REPOSITORY" | grep -q '--'; then
+    REPOSITORIES="$REPOSITORY"
+  else
+    REPOSITORIES="`ls $VOLUME/$MEDIA`"
+  fi
+
   # Iterate over existing repositories in the removable media
-  for folder in `ls $VOLUME/$MEDIA`; do
+  for folder in $REPOSITORIES; do
 
     # Sync each local repository in the removable media
     if [ -d "$VOLUME/$MEDIA/$folder/.git/annex" ]; then