1
0
mirror of https://github.com/stucki/docker-lineageos synced 2025-01-23 17:51:07 -05:00

74 lines
1.7 KiB
Bash
Raw Normal View History

2017-04-21 12:50:59 +02:00
#!/usr/bin/env bash
2014-02-02 11:52:53 +01:00
2017-04-21 13:02:43 +02:00
set -euo pipefail
2014-02-02 11:52:53 +01:00
cd $(dirname $0)
SOURCE=$(pwd)/android
CCACHE=$(pwd)/ccache
2017-01-03 19:15:12 +01:00
CONTAINER_HOME=/home/build
CONTAINER=lineageos
REPOSITORY=stucki/lineageos
2017-01-03 21:32:46 +01:00
TAG=cm-14.1
2014-12-22 18:38:37 +01:00
FORCE_BUILD=0
2016-04-04 17:54:27 +02:00
PRIVILEGED=
ENVIRONMENT=
2016-04-04 17:54:27 +02:00
2016-04-04 20:23:24 +02: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"
;;
-ws|--with-su)
ENVIRONMENT="-e WITH_SU=true"
;;
2016-04-04 20:23:24 +02:00
*)
shift # past argument or value
;;
esac
shift
2016-04-04 17:54:27 +02:00
done
2014-02-02 11:52:53 +01:00
2014-06-28 16:19:18 +02:00
# Create shared folders
# 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 17:55:06 +02:00
mkdir -p $SOURCE
mkdir -p $CCACHE
2014-02-02 11:52:53 +01:00
2017-06-06 11:44:19 +02:00
command -v docker >/dev/null \
|| { echo "command 'docker' not found."; exit 1; }
# Build image if needed
2017-06-06 11:44:19 +02:00
if [[ $FORCE_BUILD = 1 ]] || ! docker inspect $REPOSITORY:$TAG &>/dev/null; then
docker build \
--pull \
-t $REPOSITORY:$TAG \
--build-arg hostuid=$(id -u) \
--build-arg hostgid=$(id -g) \
.
# After successful build, delete existing containers
2017-06-06 11:44:19 +02:00
if docker inspect $CONTAINER &>/dev/null; then
docker rm $CONTAINER >/dev/null
fi
fi
2014-07-18 23:48:18 +02: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) || true
if [[ $IS_RUNNING == "true" ]]; then
docker attach $CONTAINER
elif [[ $IS_RUNNING == "false" ]]; then
docker start -i $CONTAINER
else
docker run $PRIVILEGED -v $SOURCE:$CONTAINER_HOME/android:Z -v $CCACHE:/srv/ccache:Z -i -t $ENVIRONMENT --name $CONTAINER $REPOSITORY:$TAG
fi
2014-02-02 11:52:53 +01:00
exit $?