#!/bin/bash # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: Apache-2.0 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4 set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR # alternatively, using https://iankelling.org/git/?p=errhandle;a=tree # source /path/errhandle/err # on my machine source /a/bin/errhandle/err [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" usage() { cat <&2; exit 1; } temp=$(getopt -l help h "$@") || usage 1 eval set -- "$temp" while true; do case $1 in -h|--help) usage ;; --) shift; break ;; *) echo "$0: unexpected args: $*" >&2 ; usage 1 ;; esac shift done read -r target <<<"$@" if [[ ! $target ]]; then echo $0: error: specify target exit 1 fi cat >/etc/btrbk/root2.conf <$tmpconf <<<"archive_exclude ${exclude}_ubuntubionic" btrbk -c $tmpconf archive /mnt/r7/amy/btrbk ssh://$target/mnt/${base}2/btrbk # swaps the vars exclude=$base done