1
0
Fork 0
env/.runenv

85 lines
1.4 KiB
Bash

#!/bin/sh
CONTAINER_IMAGE="registry.makerforce.io/ambrose/env"
CONTAINER_HOME="/home/ambrose"
OPTIND=1
workdir=""
delete=""
name=""
ports="\n\t"
volumes=""
show_help() {
cat << EOF
Usage: ${0##*/} [-hxw] [-n NAME] [-p PORT]... [-v LIST]... [CMD]...
Starts an env Docker container. If CMD is specified, starts CMD
instead of a shell.
-h display this help and exit
-x delete Docker container after exit. will loose data
-w forward \$PWD into $CONTAINER_HOME/src, and start there
-n NAME give container a NAME
-p PORT forward host PORT to container PORT
-v LIST mount volume LIST. specify as LOCAL:MOUNT
EOF
}
while getopts "hxwn:p:v:" opt; do
case "$opt" in
x)
delete="--rm "
;;
w)
workdir="\n\t--workdir $CONTAINER_HOME/src "
volumes="$volumes\n\t-v '$PWD':$CONTAINER_HOME/src "
;;
n)
name="--name $OPTARG "
;;
p)
ports="$ports-p $OPTARG:$OPTARG "
;;
v)
volumes="$volumes\n\t-v '$OPTARG' "
;;
h)
show_help
exit 0
;;
:)
echo "Option -$OPTARG requires an argument." >&2
show_help
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
show_help
exit 1
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ "$ports" = "\n\t" ]; then
ports=""
fi
docker pull $CONTAINER_IMAGE
cmd="\n\
docker run -it $delete$name$ports$workdir$volumes\n\
-v $HOME/.ssh:$CONTAINER_HOME/.ssh \n\
$CONTAINER_IMAGE \n\
$@\
"
echo
echo "Running: $cmd"
bash -c "`echo $cmd | tr -d '\n'`" # Ugh...