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
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 ########
(( $# == 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
;;
esac
-
source /a/bin/bash_unpublished/source-state
if [[ $old_host != "$MAIL_HOST" ]]; then
mexit 1
fi
-e $new_shell hostname
-new_hostname=$($new_shell hostname)
########### end initial processing, begin actually modifying things ##########