fix bug when sshing to fqdn etc
authorIan Kelling <iank@fsf.org>
Sat, 30 Mar 2019 18:56:05 +0000 (14:56 -0400)
committerIan Kelling <iank@fsf.org>
Sat, 30 Mar 2019 18:56:05 +0000 (14:56 -0400)
switch-mail-host

index b67203aabc475608a4768cbcc2204126979ef48b..9ebd2a73cd1e41731e2318eea8cc9369bb9a7375 100755 (executable)
@@ -107,6 +107,8 @@ while $new_shell $btrbk_test || $old_shell $btrbk_test; do
     sleep 2
 done
 
+new_hostname=$($new_shell hostname)
+
 ########### end initial processing, begin actually modifying things ##########
 
 restore_new_btrbk=false
@@ -121,10 +123,10 @@ if $old_shell systemctl is-active btrbk.timer; then
 fi
 
 
-$new_shell bash -s <<'EOF'
+$new_shell bash -xs <<'EOF'
 set -eE
-if mountpoint /m; then sudo umount /m; fi
-if mountpoint /o; then sudo umount /o; fi
+if mountpoint -q /m; then sudo umount /m; fi
+if mountpoint -q /o; then sudo umount /o; fi
 EOF
 
 # if new_host is not on home network, make mail.iankelling.org not resolve
@@ -132,17 +134,16 @@ EOF
 if [[ $new_host == $HOSTNAME ]] && ! $at_home; then
     echo | $wrt_shell cedit mail_host /etc/hosts || [[ $? == 1 ]] # 1 means file changed.
 else
-    $wrt_shell bash -s <<EOFOUTER
-    if ! cedit mail_host /etc/hosts <<EOF; then
-\$(grep "\b$new_host\b" /etc/hosts | awk '{print \$1}') mail.iankelling.org
+    $wrt_shell bash -xs $new_host <<'EOFOUTER'
+new_host=$1
+cedit mail_host /etc/hosts <<EOF || /etc/init.d/dnsmasq restart
+$(grep "\b$new_hostname\b" /etc/hosts | awk '{print $1}') mail.iankelling.org
 EOF
-/etc/init.d/dnsmasq restart
 EOFOUTER
 fi
 
-
 $old_shell /a/bin/distro-setup/install-my-scripts
-$old_shell primary-setup $new_host
+$old_shell primary-setup $new_hostname
 
 sudo dd of=/etc/btrbk.conf <<'EOF'
 ssh_identity /root/.ssh/home
@@ -198,7 +199,7 @@ EOF
 sudo btrbk -l debug --progress run
 $new_shell /a/bin/distro-setup/install-my-scripts
 $new_shell mount-latest-subvol
-$new_shell primary-setup $new_host
+$new_shell primary-setup $new_hostname
 
 if $restore_new_btrbk; then
     $new_shell sudo systemctl start btrbk.timer