| #!/bin/sh |
| # |
| # ssh (or, if no network, portsh) into the given device. |
| # |
| mydir=$(dirname "$0") |
| cd "$mydir" |
| |
| name=$1 |
| shift |
| |
| log() |
| { |
| echo "$@" >&2 |
| } |
| |
| |
| die() |
| { |
| log "$@" |
| exit 99 |
| } |
| |
| |
| if [ -z "$name" ]; then |
| die "Usage: $0 <configname> [command...]" |
| fi |
| |
| cmd=$(args="$*" ./run --quiet --raw "$name" -- ' |
| if [ -n "$ip6" ] && ping6 -n -c1 -w2 $ip6 >/dev/null 2>&1; then |
| echo "ssh root@$ip6" |
| elif [ -n "$ip" ] && ping -n -c1 -w2 $ip >/dev/null 2>&1; then |
| echo "ssh root@$ip" |
| elif [ -n "$serialport" ]; then |
| if [ -n "$args" ]; then |
| echo "./portsh/portsh -pgoogle $serialport" |
| else |
| echo "./portsh/port $serialport" |
| fi |
| else |
| exit 1 |
| fi |
| ') || die "Fatal: host '$name' has no live IP or serial port" |
| log ">>> $cmd --" "$@" |
| exec $cmd -- "$@" |