X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=switch-mail-host;h=eafe1044c0816c19aa7522b94445d6a3de7cec78;hp=14a11f866ab3b03ea0d51eedf833e7782a38d848;hb=7f759d320592e791a62cd0a966350e8c53ee0976;hpb=165008e5b82c81ebff1061c8f8294c3bc6e9dced diff --git a/switch-mail-host b/switch-mail-host index 14a11f8..eafe104 100644 --- a/switch-mail-host +++ b/switch-mail-host @@ -24,7 +24,7 @@ EOF restore_new_btrbk=false restore_old_btrbk=false -errcatch-cleanup() { +err-cleanup() { if $restore_new_btrbk; then e WARNING: due to failure, btrbk.timer may need manual restoration: e $new_shell sudo systemctl start btrbk.timer @@ -38,8 +38,8 @@ errcatch-cleanup() { pre="${0##*/}:" m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } -err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; } -mexit() { echo "exiting with status $1"; exit $1; } +err() { echo "$pre: ERROR: $*" >&2; } +mexit() { echo "$pre: exiting with status $1"; exit $1; } ##### begin command line parsing ######## @@ -58,20 +58,28 @@ done (( $# == 2 )) || usage 1 +if [[ ! $HOSTNAME ]]; then + err '$HOSTNAME is unset' + mexit 1 +fi case $1 in push) + old_host=$HOSTNAME new_host=$2 bbk_args="-s $old_host" new_shell="ssh $new_host" - old_host=$HOSTNAME + new_hostname=$($new_shell hostname) ;; pull) old_host=$2 + new_host=$HOSTNAME + new_hostname=$HOSTNAME bbk_args="-t $new_host" bbk_args="-s $old_host" - new_host=$HOSTNAME old_shell="ssh $old_host" + # test ssh connection + $old_shell : ;; *) err invalid first argument @@ -79,7 +87,6 @@ case $1 in ;; esac - source /a/bin/bash_unpublished/source-state if [[ $old_host != "$MAIL_HOST" ]]; then @@ -92,8 +99,6 @@ if [[ ! $new_host || ! $old_host ]]; then mexit 1 fi -e $new_shell hostname -new_hostname=$($new_shell hostname) ########### end initial processing, begin actually modifying things ##########