2014-07-18 18:10:26 -04:00
|
|
|
#!/bin/bash
|
2014-02-02 05:52:53 -05:00
|
|
|
|
|
|
|
cd $(dirname $0)
|
|
|
|
|
2016-12-25 09:19:51 -05:00
|
|
|
if [[ $OSTYPE == "darwin"* ]]; then
|
|
|
|
SOURCE=$(stat -f %N $(pwd)/android)
|
|
|
|
CCACHE=$(stat -f %N $(pwd)/ccache)
|
|
|
|
else
|
|
|
|
SOURCE=$(readlink -f $(pwd)/android)
|
|
|
|
CCACHE=$(readlink -f $(pwd)/ccache)
|
|
|
|
fi
|
|
|
|
|
2017-01-03 13:15:12 -05:00
|
|
|
CONTAINER_HOME=/home/build
|
2017-01-03 15:32:06 -05:00
|
|
|
CONTAINER=lineageos
|
|
|
|
REPOSITORY=stucki/lineageos
|
2017-01-03 15:32:46 -05:00
|
|
|
TAG=cm-14.1
|
2014-12-22 12:38:37 -05:00
|
|
|
FORCE_BUILD=0
|
2016-04-04 11:54:27 -04:00
|
|
|
PRIVILEGED=
|
|
|
|
|
2016-04-04 14:23:24 -04:00
|
|
|
while [[ $# > 0 ]]; do
|
|
|
|
key="$1"
|
|
|
|
case $key in
|
|
|
|
-r|--rebuild)
|
|
|
|
FORCE_BUILD=1
|
|
|
|
;;
|
|
|
|
-u|--enable-usb)
|
|
|
|
PRIVILEGED="--privileged -v /dev/bus/usb:/dev/bus/usb"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
shift # past argument or value
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2016-04-04 11:54:27 -04:00
|
|
|
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
|
|
|
|
2014-07-14 01:30:56 -04:00
|
|
|
# Build image if needed
|
2015-04-03 13:58:10 -04:00
|
|
|
IMAGE_EXISTS=$(docker images $REPOSITORY)
|
2014-07-14 01:30:56 -04:00
|
|
|
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
|
2016-03-13 10:18:52 -04:00
|
|
|
# Pull Ubuntu image to be sure it's up to date
|
|
|
|
echo "Fetching Docker \"ubuntu\" image..."
|
2016-08-19 13:03:30 -04:00
|
|
|
docker pull ubuntu:16.04
|
2016-03-13 10:18:52 -04:00
|
|
|
|
2015-03-15 12:38:12 -04:00
|
|
|
echo "Building Docker image $REPOSITORY:$TAG..."
|
2017-04-19 12:10:56 -04:00
|
|
|
USERID=$(id -u)
|
|
|
|
GROUPID=$(id -g)
|
|
|
|
docker build -t $REPOSITORY:$TAG --build-arg hostuid=$USERID --build-arg hostgid=$GROUPID .
|
2016-03-31 15:51:28 -04:00
|
|
|
OK=$?
|
2015-04-03 14:29:37 -04:00
|
|
|
|
|
|
|
# After successful build, delete existing containers
|
|
|
|
IS_EXISTING=$(docker inspect -f '{{.Id}}' $CONTAINER 2>/dev/null)
|
2016-03-31 15:51:28 -04:00
|
|
|
if [[ $OK -eq 0 ]] && [[ -n "$IS_EXISTING" ]]; then
|
2015-04-03 14:29:37 -04:00
|
|
|
docker rm $CONTAINER
|
|
|
|
fi
|
2014-07-14 01:30:56 -04:00
|
|
|
fi
|
|
|
|
|
2016-03-31 15:51:28 -04:00
|
|
|
if [[ $OK -ne 0 ]]; then
|
2016-04-05 15:49:12 -04:00
|
|
|
exit 1
|
2016-03-31 15:51:28 -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
|
2017-01-20 21:34:20 -05:00
|
|
|
docker run $PRIVILEGED -v $SOURCE:$CONTAINER_HOME/android:Z -v $CCACHE:/srv/ccache:Z -i -t --name $CONTAINER $REPOSITORY:$TAG
|
2014-07-14 01:30:56 -04:00
|
|
|
fi
|
2014-02-02 05:52:53 -05:00
|
|
|
|
|
|
|
exit $?
|