termux-packages/scripts/run-docker.sh

47 lines
1.1 KiB
Bash
Raw Normal View History

2016-05-28 00:24:50 +02:00
#!/bin/sh
set -e -u
HOME=/home/builder
2018-09-11 22:32:43 +02:00
UNAME=$(uname)
if [ "$UNAME" = Darwin ]; then
# Workaround for mac readlink not supporting -f.
REPOROOT=$PWD
else
REPOROOT="$(dirname $(readlink -f $0))/../"
fi
2016-05-28 00:24:50 +02:00
IMAGE_NAME=termux/package-builder
: ${CONTAINER_NAME:=termux-package-builder}
2016-05-28 00:24:50 +02:00
USER=builder
echo "Running container '$CONTAINER_NAME' from image '$IMAGE_NAME'..."
docker start $CONTAINER_NAME > /dev/null 2> /dev/null || {
echo "Creating new container..."
docker run \
2019-02-21 02:35:57 +01:00
--detach \
--name $CONTAINER_NAME \
--volume $REPOROOT:$HOME/termux-packages \
--tty \
$IMAGE_NAME
2018-09-11 22:32:43 +02:00
if [ "$UNAME" != Darwin ]; then
2019-02-12 09:23:21 +01:00
if [ $(id -u) -ne 1000 -a $(id -u) -ne 0 ]
then
2019-02-21 02:35:57 +01:00
echo "Changed builder uid/gid... (this may take a while)"
docker exec --tty $CONTAINER_NAME sudo chown -R $(id -u) $HOME
docker exec --tty $CONTAINER_NAME sudo chown -R $(id -u) /data
docker exec --tty $CONTAINER_NAME sudo usermod -u $(id -u) builder
docker exec --tty $CONTAINER_NAME sudo groupmod -g $(id -g) builder
2019-02-12 09:23:21 +01:00
fi
2018-09-11 22:32:43 +02:00
fi
}
if [ "$#" -eq "0" ]; then
2019-02-21 02:35:57 +01:00
docker exec --interactive --tty $CONTAINER_NAME bash
else
2019-02-21 02:35:57 +01:00
docker exec --interactive --tty $CONTAINER_NAME $@
fi
2016-05-28 00:24:50 +02:00