From 9daacb14025d4e4bc267260c63cb6e42f8c96c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Mon, 23 Oct 2017 21:25:22 +0200 Subject: [PATCH] A script for running commands in the docker container --- d | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 d diff --git a/d b/d new file mode 100755 index 0000000..ead6c13 --- /dev/null +++ b/d @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +imagename=mittos64 + +buildroot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" + +# Check if the docker image exists +# If not, ask if it should be built +if ! docker image ls -f reference=${imagename} | grep ${imagename} >/dev/null; then + echo "Docker image does not exist." + echo "Do you wish to build it? (This could take a while)" + read -r -p "[y/N]: " response + case "$response" in + [Yy][Ee][Ss]|[Yy]) + docker build -t ${imagename} ${buildroot}/toolchain + ;; + *) + exit + ;; + esac +fi + + +# Check if a container is already running the image +# If so, execute the command in the running container +if docker ps -f name=${imagename}-run | grep ${imagename}-run ; then + docker exec -it ${imagename}-run "$@" +else + docker run -it --rm -v ${buildroot}:/opt --name ${imagename}-run ${imagename} "$@" +fi