more verbose and robust btrbk wrappers
[distro-setup] / btrbk-run
index fa20061128281857e82fcfd444225cb147e4158e..5c1439824c9ea4dabb17879e83a7859e4a95bbc8 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
@@ -85,6 +85,7 @@ rsync-dirs() {
 }
 
 
+pre="${0##*/}:"
 m() { if $verbose; then printf "$pre %s\n"  "$*"; fi;  "$@"; }
 die() { printf "$pre %s\n" "$*" >&2;  exit 1; }
 
@@ -116,7 +117,6 @@ if [[ -s $default_args_file ]]; then
   sleep 5
 fi
 
-pre="${0##*/}:"
 cron=false
 orig_args=("$@")
 temp=$(getopt -l cron,pull-reexec,help cl:m:npqs:t:vh "$@") || usage 1
@@ -150,9 +150,18 @@ while true; do
   esac
 done
 
-# usefull commands are resume and archive
+# only tested commands are resume and archive
 cmd_arg=${1:-run}
 
+case $cmd_arg in
+  run|resume|archive) : ;;
+  *) die "untested command arg" ;;
+esac
+
+if (( $# > 1 )); then
+  die: "only 1 nonoption arg is supported"
+fi
+
 if [[ -v targets && $source ]]; then
   die "error: -t and -s are mutually exclusive"
 fi
@@ -229,8 +238,17 @@ else
     #    ;;
     *)
       prospective_mps=(/a /q)
-      if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
-        prospective_mps+=(/o)
+      if [[ $source ]]; then
+        source_state="$(ssh $source cat /a/bin/bash_unpublished/source-state)"
+        eval "$source_state"
+        source_host="$(ssh $source cat /etc/hostname)"
+        if [[ $source_host == "$MAIL_HOST" ]]; then
+          prospective_mps+=(/o)
+        fi
+      else
+        if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+          prospective_mps+=(/o)
+        fi
       fi
       ;;
   esac