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-semi-priv
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-semi-priv
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 btrbk_test
="systemctl is-active btrbk.service"
100 while $new_shell $btrbk_test ||
$old_shell $btrbk_test; do
101 echo "$0: btrbk is running on new or old host. sleeping for 8 seconds"
103 echo "$0: testing for btrbk activity in 2 seconds"
107 new_hostname
=$
($new_shell hostname
)
109 ########### end initial processing, begin actually modifying things ##########
111 restore_new_btrbk
=false
112 if $new_shell systemctl is-active btrbk.timer
; then
113 $new_shell sudo systemctl stop btrbk.timer
114 restore_new_btrbk
=true
116 restore_old_btrbk
=false
117 if $old_shell systemctl is-active btrbk.timer
; then
118 $old_shell sudo systemctl stop btrbk.timer
119 restore_old_btrbk
=true
123 $new_shell bash
-xs <<'EOF'
125 if mountpoint -q /m; then sudo umount /m; fi
126 if mountpoint -q /o; then sudo umount /o; fi
129 # previously, I was checking to see if the new mail host
130 # is on my home network, then changing my home dns
131 # to resolve on the local network, so that I didnt
132 # have to send traffic out to the internet or rely
133 # on that. However, that breaks for a laptop that roams.
134 # So, we could have a cronjob that updates that dns,
135 # however, another solution is to just use ipv6,
138 # TODO: enable ipv6 for email. exim config setting disables it.
139 # need to add vpn support. need to add firewall / routing.
140 # I think exim will try ipv6 first, so no need to disable
143 $old_shell primary-setup
$new_hostname
145 if $localhost_new; then
146 btrbk-run
-s $old_host $mp_args
148 btrbk-run
-t $new_host $mp_args
151 $new_shell primary-setup
$new_hostname
153 if $restore_new_btrbk; then
154 $new_shell sudo systemctl start btrbk.timer
156 if $restore_old_btrbk; then
157 $old_shell sudo systemctl start btrbk.timer