fix reexecing issues
authorIan Kelling <iank@fsf.org>
Sat, 11 May 2019 02:11:46 +0000 (22:11 -0400)
committerIan Kelling <iank@fsf.org>
Sat, 11 May 2019 02:11:46 +0000 (22:11 -0400)
btrbk-run

index 59631fdd75efbad9f54733a08b22975e5b5712c8..4a2816b88376ef206f4e895de6537024dbf7d25d 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
@@ -21,6 +21,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
 
+
 usage() {
   cat <<'EOF'
 btrbk-run [OPTIONS]
@@ -35,6 +36,15 @@ EOF
   exit $1
 }
 
+rsync-dirs() {
+  local host=$1
+  local path=$2
+  m rsync $dry_run_arg -ahi --relative --delete "$path" "root@$host:/"
+}
+
+
+m() { printf "%s: %s\n" "${0##*/}" "$*";  "$@"; }
+
 # latest $MAIL_HOST
 if [[ -e /b/bash_unpublished/source-semi-priv ]]; then
   source /b/bash_unpublished/source-semi-priv
@@ -97,19 +107,6 @@ if [[ -v targets && $source ]]; then
   exit 1
 fi
 
-# pull_reexec stops us from getting into an infinite loop if there is some
-# kind of weird problem
-if ! $pull_reexec && [[ $source ]]; then
-  tmpf=$(mktemp)
-  scp $source:/a/bin/distro-setup/btrbk-run $tmpf
-  if diff -q $tmpf $BASH_SOURCE; then
-    echo "$0: found newer version on host $source. reexecing"
-    install -T $tmpf /usr/local/bin/btrbk-run
-    m /usr/local/bin/btrbk-run --pull-reexec "${orig_args[@]}"
-    exit
-  fi
-fi
-
 
 echo -e "$0: options: conf_only=$conf_only\ndry_run=$dry_run\nrate_limit=$rate_limit\nverbose=$verbose\ncmd_arg=$cmd_arg"
 ### end options parsing
@@ -184,16 +181,31 @@ fi
 
 echo "mountpoints: ${mountpoints[*]}"
 
-##### end command line parsing ########
 
-rsync-dirs() {
-  local host=$1
-  local path=$2
-  m rsync $dry_run_arg -ahi --relative --delete "$path" "root@$host:/"
-}
 
+# pull_reexec stops us from getting into an infinite loop if there is some
+# kind of weird problem
+pulla=false
+for m in "${mountpoints[@]}"; do
+  if [[ $m == /a ]]; then
+    pulla=true
+    break
+  fi
+done
+if ! $pull_reexec && [[ $source ]] && ! $pulla ; then
+  tmpf=$(mktemp)
+  scp $source:/a/bin/distro-setup/btrbk-run $tmpf
+  if ! diff -q $tmpf $BASH_SOURCE; then
+    echo "$0: found newer version on host $source. reexecing"
+    install -T $tmpf /usr/local/bin/btrbk-run
+    m /usr/local/bin/btrbk-run --pull-reexec "${orig_args[@]}"
+    exit
+  fi
+fi
+
+
+##### end command line parsing ########
 
-m() { printf "%s: %s\n" "${0##*/}" "$*";  "$@"; }
 
 
 if ! which btrbk &>/dev/null; then