From: Colin P. Mccabe Date: Tue, 29 Nov 2016 22:18:35 +0000 (-0800) Subject: dssh: add login-by-name X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1d171743a8d86cb67810fb4b97b79a0ce525eda;p=cmccabe-bin dssh: add login-by-name --- diff --git a/dssh b/dssh index c67976e..a00ca4d 100755 --- a/dssh +++ b/dssh @@ -9,7 +9,50 @@ die() { exit 1 } -CONTAINER=${1} -[ "x${CONTAINER}" == "x" ] && die "You must supply a container name as the first argument." -shift -docker exec -it "${CONTAINER}" bash "${@}" +usage() { + cat </dev/null || die "docker must be on the PATH." + +if [ "x${DOCKER_IMAGE_NAME}" == "x" ]; then + if [ "x${DOCKER_IMAGE_ID}" == "x" ]; then + usage + exit 1 + fi +else + if [ "x${DOCKER_IMAGE_ID}" == "x" ]; then + : + else + echo "You must not supply both an ID and a name." + exit 1 + fi + DOCKER_IMAGE_ID=$(docker ps -f name=${DOCKER_IMAGE_NAME} -q) + [ "x${DOCKER_IMAGE_ID}" == "x" ] && \ + die "failed to find a docker image named ${DOCKER_IMAGE_NAME}" +fi + +docker exec -it "${DOCKER_IMAGE_ID}" /bin/bash