# ensure these are unused before doing anything
-e "umounting /m and /o via $new_shell"
-$new_shell bash -xs <<'EOF'
+e "On $new_host: umounting /m and /o, checking emacs"
+$new_shell bash -s <<'EOF'
set -eE
-if mountpoint -q /m; then umount /m; fi
-if mountpoint -q /o; then umount /o; fi
+if pgrep -f 'emacs --daemon' &>/dev/null; then
+ bufs="$(emacsclient --eval "$(cat /a/bin/ds/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
+ if [[ $bufs ]]; then
+ echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2
+ exit 1
+ fi
+fi
+for dir in m o; do
+ if mountpoint -q /$dir; then
+ echo On $new_host: umount /$dir
+ umount /$dir
+ fi
+done
+EOF
+
+$old_shell bash -s <<'EOF'
+if pgrep -f 'emacs --daemon' &>/dev/null; then
+ bufs="$(emacsclient --eval "$(cat /a/bin/ds/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
+ if [[ $bufs ]]; then
+ echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2
+ exit 1
+ fi
+fi
EOF
# previously, I was checking to see if the new mail host
exit $ret
fi
+# Try to prevent emacs from saving stale data it has in memory to disk. eg: files, recentf list, etc.
+# But if emacs ignores the signal, let it live.
+m $new_shell killall -q emacs ||:
+
e Running main btrbk
m btrbk-run -v $bbk_args $incremental_arg -m /o || ret=$?
if (( ret )); then