1
0
mirror of https://github.com/stucki/docker-lineageos synced 2024-12-19 17:12:29 -05:00
docker-lineageos/run.sh

69 lines
1.5 KiB
Bash
Raw Normal View History

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
CONTAINER_HOME=/home/cmbuild
2014-02-02 17:55:33 -05:00
CONTAINER=cyanogenmod
REPOSITORY=stucki/cyanogenmod
2016-01-22 08:03:08 -05:00
TAG=cm-13.0
2014-12-22 12:38:37 -05:00
FORCE_BUILD=0
2016-04-04 11:54:27 -04:00
PRIVILEGED=
while [[ $# > 0 ]]
do
key="$1"
case $key in
-r|--rebuild)
FORCE_BUILD=1
;;
-u|--enable-usb)
2016-04-04 11:54:27 -04:00
PRIVILEGED="--privileged -v /dev/bus/usb:/dev/bus/usb"
;;
*)
shift # past argument or value
;;
esac
shift
done
2014-02-02 05:52:53 -05:00
2014-06-28 10:19:18 -04:00
# Create shared folders
2016-04-04 11:55:06 -04:00
mkdir -p $SOURCE
mkdir -p $CCACHE
2014-02-02 05:52:53 -05:00
# Build image if needed
2015-04-03 13:58:10 -04:00
IMAGE_EXISTS=$(docker images $REPOSITORY)
if [ $? -ne 0 ]; then
echo "docker command not found"
exit $?
2015-04-03 13:58:10 -04:00
elif [[ $FORCE_BUILD = 1 ]] || ! echo "$IMAGE_EXISTS" | grep -q "$TAG"; then
# Pull Ubuntu image to be sure it's up to date
echo "Fetching Docker \"ubuntu\" image..."
docker pull ubuntu:14.04
2015-03-15 12:38:12 -04:00
echo "Building Docker image $REPOSITORY:$TAG..."
docker build -t $REPOSITORY:$TAG .
# After successful build, delete existing containers
IS_EXISTING=$(docker inspect -f '{{.Id}}' $CONTAINER 2>/dev/null)
if [[ -n "$IS_EXISTING" ]]; then
docker rm $CONTAINER
fi
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.
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
2016-04-04 11:54:27 -04:00
docker run $PRIVILEGED -v $SOURCE:$CONTAINER_HOME/android -v $CCACHE:/srv/ccache -i -t --name $CONTAINER $REPOSITORY:$TAG
fi
2014-02-02 05:52:53 -05:00
exit $?