3 source /usr
/local
/lib
/err
7 Usage: ${0##*/} OLD_HOST NEW_HOST
9 Turn off mail receiving on OLD_HOST, run btrbk to move mail to NEW_HOST,
10 turn on mail receiving on NEW_HOST. Assumes we want to move all
11 filesystems unless passing -o.
13 -o Only btrbk /o, instead of all filesystems.
14 -h|--help Print help and exit.
16 I used to adjust home network dns so NEW_HOST resolves locally if it is
17 on the local network, but its simpler just not to and just rely
18 on the internet. Email can wait.
20 Note: Uses GNU getopt options parsing style
25 restore_new_btrbk
=false
26 restore_old_btrbk
=false
28 if $restore_new_btrbk; then
29 $new_shell sudo systemctl start btrbk.timer
31 if $restore_old_btrbk; then
32 $old_shell sudo systemctl start btrbk.timer
35 _errcatch_cleanup
=cleanup
# used by sourced err
38 m
() { printf "$pre %s\n" "$*"; "$@"; }
39 e
() { printf "$pre %s\n" "$*"; }
41 ##### begin command line parsing ########
43 temp
=$
(getopt
-l help owh
"$@") || usage
1
48 -o) mp_args
="-m /o"; shift ;;
51 *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
56 (( $# == 2 )) || usage
1
60 source /a
/bin
/bash_unpublished
/source-state
62 if [[ $old_host != "$MAIL_HOST" ]]; then
63 read -r -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N "
64 if [[ $REPLY != [yY
] ]]; then
69 if [[ $new_host == "$HOSTNAME" ]]; then
74 new_shell
="ssh $new_host"
77 old_shell
="ssh $old_host"
78 if [[ $old_host == "$HOSTNAME" ]]; then
82 if [[ ! $new_host ||
! $old_host ]]; then
83 echo "$0: bad args. see script"
88 source /a
/bin
/bash_unpublished
/source-state
91 new_hostname
=$
($new_shell hostname
)
93 ########### end initial processing, begin actually modifying things ##########
95 if $new_shell systemctl is-active btrbk.timer
; then
96 m
$new_shell sudo systemctl stop btrbk.timer
97 restore_new_btrbk
=true
99 if $old_shell systemctl is-active btrbk.timer
; then
100 m
$old_shell sudo systemctl stop btrbk.timer
101 restore_old_btrbk
=true
104 btrbk_test
="systemctl is-active btrbk.service"
105 while [[ $
($new_shell $btrbk_test) != inactive
]] ||
[[ $
($old_shell $btrbk_test) != inactive
]]; do
106 echo "$0: btrbk is running on new or old host. sleeping for 8 seconds"
108 echo "$0: testing for btrbk activity in 2 seconds"
112 # ensure these are unused before doing anything
114 e
"umounting /m and /o via $new_shell"
115 $new_shell bash
-xs <<'EOF'
117 if mountpoint -q /m; then sudo umount /m; fi
118 if mountpoint -q /o; then sudo umount /o; fi
121 # previously, I was checking to see if the new mail host
122 # is on my home network, then changing my home dns
123 # to resolve on the local network, so that I didnt
124 # have to send traffic out to the internet or rely
125 # on that. However, that breaks for a laptop that roams.
126 # So, we could have a cronjob that updates that dns,
127 # however, another solution is to just use ipv6,
130 # TODO: enable ipv6 for email. exim config setting disables it.
131 # need to add vpn support. need to add firewall / routing.
132 # I think exim will try ipv6 first, so no need to disable
135 m
$old_shell /a
/exe
/primary-setup
$new_hostname
137 if $localhost_new; then
138 m btrbk-run
-v -s $old_host $mp_args
140 m btrbk-run
-v -t $new_host $mp_args
143 m
$new_shell /a
/exe
/primary-setup
$new_hostname