improvements
[distro-setup] / switch-mail-host
index 0a80d2c2c2eb048e082cf3b701bdd9352506bf0e..12bf126e1f2512179915933ebacf0ebeb6ec0513 100644 (file)
@@ -150,11 +150,32 @@ done
 
 # 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
@@ -185,6 +206,10 @@ if ! m $old_shell /a/exe/primary-setup $new_hostname; then
   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