+# only tested commands are resume and archive
+cmd_arg=${1:-run}
+
+case $cmd_arg in
+ run|resume|archive) : ;;
+ *) die "untested command arg" ;;
+esac
+
+if (( $# > 1 )); then
+ die: "only 1 nonoption arg is supported"
+fi
+
+if [[ -v targets && $source ]]; then
+ die "error: -t and -s are mutually exclusive"
+fi
+
+if $verbose; then
+ printf "$pre options: conf_only=%s\ndry_run=%s\nrate_limit=%s\nverbose=%s\ncmd_arg=%s" "$conf_only" "$dry_run" "$rate_limit" "$verbose" "$cmd_arg"
+fi
+### end options parsing
+
+# TODO: i wonder if there should be an option to send to the default
+# targets, plus any given on the command line.
+
+# set default targets
+if [[ ! -v targets && ! $source ]]; then
+ if [[ $HOSTNAME != "$MAIL_HOST" ]] && $cron ; then
+ echo "MAIL_HOST=$MAIL_HOST, nothing to do"
+ exit 0
+ fi
+ case $HOSTNAME in
+ kw|x2)
+ if ping -q -c1 -w1 iank.vpn.office.fsf.org &>/dev/null; then
+ home=iank.vpn.office.fsf.org
+ else
+ home=b8.nz
+ fi
+ ;;&
+ kw)
+ targets=($home x2)
+ ;;
+ x2)
+ targets=($home kw)
+ ;;
+ tp)
+ targets=(frodo kd)
+ # might not be connected to the vpn
+ if timeout -s 9 10 ssh kw :; then
+ targets+=(kw)
+ fi
+ ;;
+ kd)
+ targets=(frodo tp)
+ # might not be connected to the vpn
+ if timeout -s 9 10 ssh kw :; then
+ targets+=(kw)
+ fi
+ ;;
+ *)
+ die "error: no default targets for this host, use -t"
+ ;;
+ esac