2017-04-21 06:50:59 -04:00
|
|
|
#!/usr/bin/env bash
|
2014-02-02 05:52:53 -05:00
|
|
|
|
2017-04-21 07:02:43 -04:00
|
|
|
set -euo pipefail
|
|
|
|
|
2014-02-02 05:52:53 -05:00
|
|
|
cd $(dirname $0)
|
|
|
|
|
2017-04-21 06:48:19 -04:00
|
|
|
SOURCE=$(pwd)/android
|
|
|
|
CCACHE=$(pwd)/ccache
|
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=
|
2017-06-25 15:23:20 -04:00
|
|
|
ENVIRONMENT=
|
2016-04-04 11:54:27 -04:00
|
|
|
|
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"
|
|
|
|
;;
|
2017-06-25 15:23:20 -04:00
|
|
|
-ws|--with-su)
|
|
|
|
ENVIRONMENT="-e WITH_SU=true"
|
|
|
|
;;
|
2016-04-04 14:23:24 -04:00
|
|
|
*)
|
|
|
|
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
|
2017-05-30 13:38:12 -04:00
|
|
|
# Although Docker would create non-existing directories on the fly,
|
|
|
|
# we need to have them owned by the user (and not root), to be able
|
|
|
|
# to write in them, which is a necessity for startup.sh
|
2016-04-04 11:55:06 -04:00
|
|
|
mkdir -p $SOURCE
|
|
|
|
mkdir -p $CCACHE
|
2014-02-02 05:52:53 -05:00
|
|
|
|
2017-06-06 05:44:19 -04:00
|
|
|
command -v docker >/dev/null \
|
|
|
|
|| { echo "command 'docker' not found."; exit 1; }
|
|
|
|
|
2014-07-14 01:30:56 -04:00
|
|
|
# Build image if needed
|
2017-06-06 05:44:19 -04:00
|
|
|
if [[ $FORCE_BUILD = 1 ]] || ! docker inspect $REPOSITORY:$TAG &>/dev/null; then
|
|
|
|
|
2017-05-29 08:40:45 -04:00
|
|
|
docker build \
|
|
|
|
--pull \
|
|
|
|
-t $REPOSITORY:$TAG \
|
|
|
|
--build-arg hostuid=$(id -u) \
|
|
|
|
--build-arg hostgid=$(id -g) \
|
|
|
|
.
|
2015-04-03 14:29:37 -04:00
|
|
|
|
|
|
|
# After successful build, delete existing containers
|
2017-06-06 05:44:19 -04:00
|
|
|
if docker inspect $CONTAINER &>/dev/null; then
|
2017-06-06 05:27:31 -04:00
|
|
|
docker rm $CONTAINER >/dev/null
|
2015-04-03 14:29:37 -04:00
|
|
|
fi
|
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.
|
2017-04-24 16:56:01 -04:00
|
|
|
IS_RUNNING=$(docker inspect -f '{{.State.Running}}' $CONTAINER 2>/dev/null) || true
|
2014-07-14 01:30:56 -04:00
|
|
|
if [[ $IS_RUNNING == "true" ]]; then
|
|
|
|
docker attach $CONTAINER
|
|
|
|
elif [[ $IS_RUNNING == "false" ]]; then
|
|
|
|
docker start -i $CONTAINER
|
|
|
|
else
|
2017-06-25 15:23:20 -04:00
|
|
|
docker run $PRIVILEGED -v $SOURCE:$CONTAINER_HOME/android:Z -v $CCACHE:/srv/ccache:Z -i -t $ENVIRONMENT --name $CONTAINER $REPOSITORY:$TAG
|
2014-07-14 01:30:56 -04:00
|
|
|
fi
|
2014-02-02 05:52:53 -05:00
|
|
|
|
|
|
|
exit $?
|