#!/bin/sh

if hash wget 2>&1; then
    fetch="wget -O- -q"
elif hash curl 2>&1; then
    fetch="curl -s"
elif hash GET 2>&1; then
    fetch=GET
else
    echo "Couldn't find an HTTP client in your PATH" >&2
    exit 1
fi

server=$($fetch http://scripts.mit.edu/ | sed -n "s/^You are currently connected to \(.*\)\..$/\1/p")

if [ -z "$server" ]; then
    echo "Couldn't find your server." >&2
    exit 1
fi

exec ssh "$server" "$@"
