2014-07-18 18:10:26 -04:00
|
|
|
#!/bin/bash
|
2014-02-02 05:52:53 -05:00
|
|
|
|
|
|
|
cd $(dirname $0)
|
|
|
|
|
|
|
|
SOURCE=$(pwd)/android
|
2014-06-28 10:19:18 -04:00
|
|
|
CCACHE=$(pwd)/ccache
|
2014-07-14 01:30:56 -04:00
|
|
|
CONTAINER_HOME=/home/cmbuild
|
2014-02-02 17:55:33 -05:00
|
|
|
CONTAINER=cyanogenmod
|
|
|
|
REPOSITORY=stucki/cyanogenmod
|
2015-03-15 12:38:12 -04:00
|
|
|
TAG=cm-12.1
|
2014-12-22 12:38:37 -05:00
|
|
|
FORCE_BUILD=0
|
2014-02-02 05:52:53 -05:00
|
|
|
|
2014-06-28 10:19:18 -04:00
|
|
|
# Create shared folders
|
2014-07-14 01:30:56 -04:00
|
|
|
mkdir -p $SOURCE
|
2014-06-28 10:19:18 -04:00
|
|
|
mkdir -p $CCACHE
|
2014-02-02 05:52:53 -05:00
|
|
|
|
2014-07-14 01:30:56 -04:00
|
|
|
# Build image if needed
|
2015-03-15 12:38:12 -04:00
|
|
|
IMAGE_EXISTS=$(docker images $REPOSITORY | grep "$TAG")
|
2014-07-14 01:30:56 -04:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "docker command not found"
|
|
|
|
exit $?
|
2014-12-22 12:38:37 -05:00
|
|
|
elif [[ -z $IMAGE_EXISTS ]] || [[ $FORCE_BUILD = 1 ]]; then
|
2015-03-15 12:38:12 -04:00
|
|
|
echo "Building Docker image $REPOSITORY:$TAG..."
|
|
|
|
docker build -t $REPOSITORY:$TAG .
|
2014-07-14 01:30:56 -04:00
|
|
|
fi
|
|
|
|
|
2014-07-18 17:48:18 -04:00
|
|
|
# With the given name $CONTAINER, reconnect to running container, start
|
|
|
|
# an existing/stopped container or run a new one if one does not exist.
|
2014-07-14 01:30:56 -04:00
|
|
|
IS_RUNNING=$(docker inspect -f '{{.State.Running}}' $CONTAINER 2>/dev/null)
|
|
|
|
if [[ $IS_RUNNING == "true" ]]; then
|
|
|
|
docker attach $CONTAINER
|
|
|
|
elif [[ $IS_RUNNING == "false" ]]; then
|
|
|
|
docker start -i $CONTAINER
|
|
|
|
else
|
2015-03-15 12:38:12 -04:00
|
|
|
docker run -v $SOURCE:$CONTAINER_HOME/android -v $CCACHE:/srv/ccache -i -t --name $CONTAINER $REPOSITORY:$TAG
|
2014-07-14 01:30:56 -04:00
|
|
|
fi
|
2014-02-02 05:52:53 -05:00
|
|
|
|
|
|
|
exit $?
|