+pre=btrbk-run
+
+script_name="${BASH_SOURCE[0]}"
+script_name="${script_name##*/}"
+d() {
+ if $dry_run || $conf_only; then
+ printf "$pre dry-run: %s\n" "$*"
+ else
+ printf "$pre running: %s\n" "$*"
+ "$@"
+ fi
+}
+m() { if $verbose; then printf "$pre %s\n" "$*"; fi; "$@"; }
+e() { printf "$pre %s\n" "$*"; }
+die() { printf "$pre error: %s\n" "$*" >&2; echo "$pre exiting with status 1" >&2; exit 1; }
+mexit() { echo "$pre exiting with status $1"; exit $1; }
+
+uninstalled-file-die() {
+ die "uninstalled file $1. run install-my-scripts or rerun with -f"
+}
+
+set-location() {
+ case $HOSTNAME in
+ kw)
+ at_work=true
+ ;;
+ kd|frodo)
+ at_home=true
+ ;;
+ x2|x3|sy)
+ if [[ $(dig +short @10.2.0.1 -x 10.2.0.2 2>&1 ||:) == kd.b8.nz. ]] \
+ && ip n show 10.2.0.1 | grep . &>/dev/null; then
+ at_home=true
+ elif ping -q -c1 -w1 hal.office.fsf.org &>/dev/null \
+ && ip n show 192.168.0.26 | grep . &>/dev/null; then
+ at_work=true
+ fi
+ ;;
+ esac
+}
+
+exit-if-no-default-targets() {
+ if ! $force && [[ $HOSTNAME != "$MAIL_HOST" ]]; then
+ echo "MAIL_HOST=$MAIL_HOST, nothing to do"
+ mexit 0
+ fi
+ case $HOSTNAME in
+ kw|kd|frodo|x2|x3|sy) : ;;
+ *)
+ die "error: no default targets for this host, use -t"
+ ;;
+ esac
+}
+
+add-x3-target() {
+ # main work machine
+ if ping -q -c1 -w1 x3.office.fsf.org &>/dev/null; then
+ targets+=(x3.office.fsf.org)
+ elif ping -q -c1 -w1 $h.b8.nz &>/dev/null; then
+ # in case we took it home
+ targets+=(x3.b8.nz)
+ else
+ targets+=(x3wg.b8.nz)
+ fi
+}
+
+add-wireless-target-h() {
+ if ping -q -c1 -w1 $h.b8.nz &>/dev/null; then
+ targets+=($h.b8.nz)
+ elif ping -q -c1 -w1 ${h}w.b8.nz &>/dev/null; then
+ targets+=(${h}w.b8.nz)
+ fi
+}
+
+qconf() {
+ case $sub in
+ q)
+ # q has sensitive data i dont want to backup for so long
+ cat >>/etc/btrbk$conf_suf.conf <<EOF
+snapshot_preserve $q_preserve
+snapshot_preserve_min 2h
+snapshot_dir btrbk
+target_preserve $q_preserve
+target_preserve_min 2h
+EOF
+ ;;
+ esac
+
+}