better checking for uninstalled changes in btrfs send related scripts
authorIan Kelling <ian@iankelling.org>
Wed, 26 Jul 2023 02:31:11 +0000 (22:31 -0400)
committerIan Kelling <ian@iankelling.org>
Wed, 26 Jul 2023 02:31:11 +0000 (22:31 -0400)
btrbk-run
switch-mail-host

index c33ed66904832bff7ecdcf0b5873413098395ed5..140f9e6053fdef509aace78d1186fee1c0abe26f 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
@@ -413,6 +413,26 @@ fi
 echo "mountpoints: ${mountpoints[*]}"
 
 
+uninstalled-file-die() {
+  err "uninstalled file $1. run install-my-scripts or rerun with -f"
+  exit 1
+}
+if ! $force; then
+  install_bin_files=(
+    mount-latest-subvol
+    check-subvol-stale
+    btrbk-run
+  )
+  for f in ${install_bin_files[@]}; do
+    if ! diff -q /a/bin/ds/$f /usr/local/bin/$f; then
+      uninstalled-file-die $f
+    fi
+  done
+  if ! diff -q /a/bin/errhandle/err /usr/local/lib/err; then
+    uninstalled-file-die err
+  fi
+fi
+
 
 # pull_reexec stops us from getting into an infinite loop if there is some
 # kind of weird problem
index 0132819ba491fddd6299c7bca20d357d5d4149ee..d0117af58203015ec87fe91594b9df7756621c84 100644 (file)
@@ -61,14 +61,18 @@ fi
 mail_only=false
 host2_only=false
 force=false
+pull_reexec=false
 mp_args="-m /o,/a,/ar,/q,/qd,/qr"
-temp=$(getopt -l force,help aioh "$@") || usage 1
+orig_args=("$@")
+temp=$(getopt -l force,pull-reexec,help aioh "$@") || usage 1
 eval set -- "$temp"
 while true; do
   case $1 in
     -a) snapshot_arg=resume ;;
     --force) force=true ;;
     -i) incremental_arg="-i" ;;
+    # internal option for rerunning under newer old_host when doing pull
+    --pull-reexec) pull_reexec=true;;
     -o)
       mail_only=true ;;
     -h|--help) usage ;;
@@ -86,6 +90,28 @@ if [[ ! $HOSTNAME ]]; then
   exit 1
 fi
 
+uninstalled-file-die() {
+  err "uninstalled file $1. run install-my-scripts or rerun with -f"
+  exit 1
+}
+
+if ! $force; then
+  install_bin_files=(
+    mount-latest-subvol
+    check-subvol-stale
+    btrbk-run
+    switch-mail-host
+  )
+  for f in ${install_bin_files[@]}; do
+    if ! diff -q /a/bin/ds/$f /usr/local/bin/$f; then
+      uninstalled-file-die $f
+    fi
+  done
+  if ! diff -q /a/bin/errhandle/err /usr/local/lib/err; then
+    uninstalled-file-die err
+  fi
+fi
+
 source /a/bin/bash_unpublished/source-state
 
 direction=$1
@@ -108,7 +134,6 @@ case $direction in
     new_hostname=$HOSTNAME
     bbk_args="-s $old_host"
     old_shell="ssh -F $HOME/.ssh/confighome root@$old_host"
-    old_shelliank="ssh -F $HOME/.ssh/confighome iank@$old_host"
     # tests ssh connection. crafted this to not need to do escape chars
     f=/a/bin/bash_unpublished/source-state
     if ! old_info=($($old_shell "hostname; sed -n s,.*MAIL_HOST=,,p $f; sed -n s,.*HOST2=,,p $f")); then
@@ -119,6 +144,18 @@ case $direction in
     old_hostname=${old_info[0]}
     MAIL_HOST=${old_info[1]}
     HOST2=${old_info[2]}
+
+    if ! $mail_only && ! $pull_reexec ; then
+      tmpf=$(mktemp)
+      m scp -F $HOME/.ssh/confighome root@$old_host:/usr/local/bin/switch-mail-host $tmpf
+      if ! diff -q $tmpf ${BASH_SOURCE[0]}; then
+        e "found different version on old_host=$old_hostname, reexecing"
+        install -T $tmpf /usr/local/bin/switch-mail-host
+        m /usr/local/bin/switch-mail-host --pull-reexec "${orig_args[@]}"
+        mexit 0
+      fi
+    fi
+
     ;;
   *)
     err invalid first argument