From: Ian Kelling Date: Wed, 26 Jul 2023 02:31:11 +0000 (-0400) Subject: better checking for uninstalled changes in btrfs send related scripts X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=28a58715872fc0f002f268369c82085da0e25b3f;p=distro-setup better checking for uninstalled changes in btrfs send related scripts --- diff --git a/btrbk-run b/btrbk-run index c33ed66..140f9e6 100644 --- 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 diff --git a/switch-mail-host b/switch-mail-host index 0132819..d0117af 100644 --- a/switch-mail-host +++ b/switch-mail-host @@ -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