4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
8 Usage: ${0##*/} OLD_HOST NEW_HOST
10 Adjust home network dns so NEW_HOST resolves locally if it is on the
11 local network. Turn off mail receiving on OLD_HOST, run btrbk to move
12 mail to NEW_HOST, turn on mail receiving on NEW_HOST.
14 -o Only btrbk /o, instead of all filesystems.
15 -w Don't try to ssh to wrt. Should only be used in unusual network situation.
16 -h|--help Print help and exit.
18 Note: Uses GNU getopt options parsing style
23 ##### begin command line parsing ########
25 update_wrt
=true
# default
26 temp
=$
(getopt
-l help owh
"$@") || usage
1
31 -o) mp_args
="-m /o"; shift ;;
32 -w) update_wrt
=false
; shift ;;
35 *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
40 (( $# == 2 )) || usage
1
44 source /a
/bin
/bash_unpublished
/source-state
46 if [[ $old_host != $MAIL_HOST ]]; then
47 read -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N "
48 if [[ $REPLY != [yY
] ]]; then
53 if [[ $new_host == "$HOSTNAME" ]]; then
58 new_shell
="ssh $new_host"
61 old_shell
="ssh $old_host"
62 if [[ $old_host == "$HOSTNAME" ]]; then
66 if [[ ! $new_host ||
! $old_host ]]; then
67 echo "$0: bad args. see script"
72 if timeout
-s 9 5 ssh-keyscan
-p 2220 -t rsa
10.0.0.1 2>/dev
/null |
grep -qFx '[10.0.0.1]:2220 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCH+/h1dGEfKEusBblndU2e6QT4wLCm5+yqr/sqh/0X9YfjR7BfWWm8nNmuP55cYc+Wuf5ljB1H1acXEcsl1y8e0j3agHfF0V74FE1N1zz5nn2Ep8NHnmqgEhza38ZxMPh+4p3X7zklEKU7+3SzybKBi8sg0wLzlS2LM0JaUN80zR2sK11Kye3dURUXPk78u5wodOkgcEYRwSYaDMJlUzWP+poRXIDJwFaMQnwmxbl/c84yOyaU0x/d6hFwoRscWecihX+vvBNeSyxR4xr2HDOyUWwJkctyAgt2p7w3tfkXOKcCRzTAjGVIMQLTvo0sG/yJbcyHoEFdFybCsgDvfyYn'; then
75 echo "$0: at_home = $at_home"
77 source /a
/bin
/bash_unpublished
/source-state
78 #### begin convert private hostnames to public hostnames ####
80 # for var in old_host new_host; do
83 # eval $var=$HOME_DOMAIN
88 #### end convert private hostnames to public hostnames ####
91 # because our port forward is not robust enough, we can't use proxy command,
92 # todo: setup vpn so this is all taken care of.
93 if ! $update_wrt; then
96 wrt_shell
="ssh wrt.b8.nz"
99 new_hostname
=$
($new_shell hostname
)
101 ########### end initial processing, begin actually modifying things ##########
103 restore_new_btrbk
=false
104 if $new_shell systemctl is-active btrbk.timer
; then
105 $new_shell sudo systemctl stop btrbk.timer
106 echo "$0: note: stopped btrbk.timer on $new_host"
107 restore_new_btrbk
=true
109 restore_old_btrbk
=false
110 if $old_shell systemctl is-active btrbk.timer
; then
111 $old_shell sudo systemctl stop btrbk.timer
112 echo "$0: note: stopped btrbk.timer on $old_host"
113 restore_old_btrbk
=true
116 btrbk_test
="systemctl is-active btrbk.service"
117 while [[ $
($new_shell $btrbk_test) != inactive
]] ||
[[ $
($old_shell $btrbk_test) != inactive
]]; do
118 echo "$0: btrbk is running on new or old host. sleeping for 8 seconds"
120 echo "$0: testing for btrbk activity in 2 seconds"
125 $new_shell bash
-xs <<'EOF'
127 if mountpoint -q /m; then sudo umount /m; fi
128 if mountpoint -q /o; then sudo umount /o; fi
131 # previously, I was checking to see if the new mail host
132 # is on my home network, then changing my home dns
133 # to resolve on the local network, so that I didnt
134 # have to send traffic out to the internet or rely
135 # on that. However, that breaks for a laptop that roams.
136 # So, we could have a cronjob that updates that dns,
137 # however, another solution is to just use ipv6,
140 # TODO: enable ipv6 for email. exim config setting disables it.
141 # need to add vpn support. need to add firewall / routing.
142 # I think exim will try ipv6 first, so no need to disable
145 $old_shell /a
/exe
/primary-setup
$new_hostname
147 if $localhost_new; then
148 btrbk-run
-s $old_host $mp_args
150 btrbk-run
-t $new_host $mp_args
153 $new_shell /a
/exe
/primary-setup
$new_hostname
155 if $restore_new_btrbk; then
156 $new_shell sudo systemctl start btrbk.timer
158 if $restore_old_btrbk; then
159 $old_shell sudo systemctl start btrbk.timer