1
0
mirror of https://github.com/stucki/docker-lineageos synced 2025-01-09 17:39:47 -05:00

73 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
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=
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"
;;
*)
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
2016-04-04 17:55:06 +02:00
mkdir -p $SOURCE
mkdir -p $CCACHE
2014-02-02 11:52:53 +01:00
# Build image if needed
2015-04-03 19:58:10 +02:00
IMAGE_EXISTS=$(docker images $REPOSITORY)
if [ $? -ne 0 ]; then
echo "docker command not found"
exit $?
2015-04-03 19:58:10 +02: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..."
2016-08-19 20:03:30 +03:00
docker pull ubuntu:16.04
2015-03-15 17:38:12 +01:00
echo "Building Docker image $REPOSITORY:$TAG..."
USERID=$(id -u)
GROUPID=$(id -g)
docker build -t $REPOSITORY:$TAG --build-arg hostuid=$USERID --build-arg hostgid=$GROUPID .
2016-03-31 21:51:28 +02:00
OK=$?
# After successful build, delete existing containers
IS_EXISTING=$(docker inspect -f '{{.Id}}' $CONTAINER 2>/dev/null)
2016-03-31 21:51:28 +02:00
if [[ $OK -eq 0 ]] && [[ -n "$IS_EXISTING" ]]; then
docker rm $CONTAINER
fi
fi
2016-03-31 21:51:28 +02:00
if [[ $OK -ne 0 ]]; then
2016-04-05 21:49:12 +02:00
exit 1
2016-03-31 21:51:28 +02:00
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)
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 --name $CONTAINER $REPOSITORY:$TAG
fi
2014-02-02 11:52:53 +01:00
exit $?