forked from thomasloven/mittos64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d
executable file
·31 lines (26 loc) · 927 Bytes
/
d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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 -q -f reference=${imagename}) ]]; 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
if [[ $(docker ps -q -f name=${imagename}-run) ]]; then
docker exec -it -u $(id -u):$(id -g) ${imagename}-run "$@"
else
docker run -it --rm -v ${buildroot}:/opt --name ${imagename}-run -u $(id -u):$(id -g) ${imagename} "$@"
fi