1
0
Fork 0
env/.runenv

86 lines
1.4 KiB
Plaintext
Raw Normal View History

2018-04-01 21:36:34 +08:00
#!/bin/sh
2018-04-02 11:39:51 +08:00
CONTAINER_IMAGE="registry.labs.0x.no/env"
CONTAINER_HOME="/home/ambrose"
2018-04-01 22:44:55 +08:00
OPTIND=1
2018-04-02 12:25:14 +08:00
workdir=""
2018-04-01 22:44:55 +08:00
delete=""
name=""
2018-04-02 11:39:51 +08:00
ports="\n\t"
2018-04-01 22:44:55 +08:00
volumes=""
2018-04-01 22:55:11 +08:00
show_help() {
cat << EOF
2018-04-02 12:19:49 +08:00
Usage: ${0##*/} [-hxw] [-n NAME] [-p PORT]... [-v LIST]... [CMD]...
2018-04-01 22:55:11 +08:00
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
2018-04-02 12:25:14 +08:00
-w forward \$PWD into $CONTAINER_HOME/src, and start there
2018-04-02 11:39:51 +08:00
-n NAME give container a NAME
2018-04-01 22:55:11 +08:00
-p PORT forward host PORT to container PORT
-v LIST mount volume LIST. specify as LOCAL:MOUNT
EOF
}
2018-04-02 12:19:49 +08:00
while getopts "hxwn:p:v:" opt; do
2018-04-01 22:44:55 +08:00
case "$opt" in
x)
delete="--rm "
;;
2018-04-02 12:19:49 +08:00
w)
2018-04-02 12:25:14 +08:00
workdir="\n\t--workdir $CONTAINER_HOME/src "
2018-04-08 22:36:35 +08:00
volumes="$volumes\n\t-v '$PWD':$CONTAINER_HOME/src "
2018-04-02 11:39:51 +08:00
;;
2018-04-01 22:44:55 +08:00
n)
name="--name $OPTARG "
;;
p)
2018-04-02 11:39:51 +08:00
ports="$ports-p $OPTARG:$OPTARG "
2018-04-01 22:44:55 +08:00
;;
v)
2018-04-08 22:36:35 +08:00
volumes="$volumes\n\t-v '$OPTARG' "
2018-04-01 22:44:55 +08:00
;;
2018-04-01 22:55:11 +08:00
h)
show_help
exit 0
;;
2018-04-01 22:44:55 +08:00
:)
echo "Option -$OPTARG requires an argument." >&2
2018-04-01 22:55:11 +08:00
show_help
2018-04-01 22:44:55 +08:00
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
2018-04-01 22:55:11 +08:00
show_help
2018-04-01 22:44:55 +08:00
exit 1
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
2018-04-02 11:39:51 +08:00
if [ "$ports" = "\n\t" ]; then
ports=""
fi
docker pull $CONTAINER_IMAGE
2018-04-01 22:44:55 +08:00
cmd="\n\
2018-04-02 12:25:14 +08:00
docker run -it $delete$name$ports$workdir$volumes\n\
2018-04-02 11:39:51 +08:00
-v $HOME/.ssh:$CONTAINER_HOME/.ssh \n\
$CONTAINER_IMAGE \n\
2018-04-01 22:44:55 +08:00
$@\
"
echo
echo "Running: $cmd"
2018-04-08 22:36:35 +08:00
bash -c "`echo $cmd | tr -d '\n'`" # Ugh...
2018-04-01 21:36:34 +08:00