2016-05-28 00:24:50 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e -u
|
|
|
|
|
2020-06-10 14:38:41 +02:00
|
|
|
CONTAINER_HOME_DIR=/home/builder
|
2018-09-11 22:32:43 +02:00
|
|
|
UNAME=$(uname)
|
|
|
|
if [ "$UNAME" = Darwin ]; then
|
2017-07-15 11:37:17 +02:00
|
|
|
# Workaround for mac readlink not supporting -f.
|
|
|
|
REPOROOT=$PWD
|
|
|
|
else
|
|
|
|
REPOROOT="$(dirname $(readlink -f $0))/../"
|
|
|
|
fi
|
2017-07-14 00:27:46 +02:00
|
|
|
|
2019-08-02 16:39:27 +02:00
|
|
|
: ${TERMUX_BUILDER_IMAGE_NAME:=termux/package-builder}
|
2018-07-23 01:34:06 +02:00
|
|
|
: ${CONTAINER_NAME:=termux-package-builder}
|
2016-05-28 00:24:50 +02:00
|
|
|
|
2017-07-21 15:34:38 +02:00
|
|
|
USER=builder
|
2017-03-02 12:15:27 +01:00
|
|
|
|
2020-09-27 23:36:23 +02:00
|
|
|
if [ -n "${TERMUX_DOCKER_USE_SUDO-}" ]; then
|
|
|
|
SUDO="sudo"
|
|
|
|
else
|
|
|
|
SUDO=""
|
|
|
|
fi
|
|
|
|
|
2019-08-02 16:39:27 +02:00
|
|
|
echo "Running container '$CONTAINER_NAME' from image '$TERMUX_BUILDER_IMAGE_NAME'..."
|
2016-06-04 00:41:30 +02:00
|
|
|
|
2021-07-27 18:15:35 +02:00
|
|
|
# Check whether attached to tty and adjust docker flags accordingly.
|
|
|
|
if [ -t 1 ]; then
|
2020-01-23 20:27:06 +01:00
|
|
|
DOCKER_TTY=" --tty"
|
2021-07-27 18:15:35 +02:00
|
|
|
else
|
|
|
|
DOCKER_TTY=""
|
2020-01-23 20:27:06 +01:00
|
|
|
fi
|
|
|
|
|
2020-09-27 23:36:23 +02:00
|
|
|
$SUDO docker start $CONTAINER_NAME >/dev/null 2>&1 || {
|
2016-06-04 00:41:30 +02:00
|
|
|
echo "Creating new container..."
|
2020-09-27 23:36:23 +02:00
|
|
|
$SUDO docker run \
|
2019-02-21 02:35:57 +01:00
|
|
|
--detach \
|
|
|
|
--name $CONTAINER_NAME \
|
2020-06-10 14:38:41 +02:00
|
|
|
--volume $REPOROOT:$CONTAINER_HOME_DIR/termux-packages \
|
2019-02-21 02:35:57 +01:00
|
|
|
--tty \
|
2019-08-02 16:39:27 +02:00
|
|
|
$TERMUX_BUILDER_IMAGE_NAME
|
2020-01-23 20:27:06 +01:00
|
|
|
if [ "$UNAME" != Darwin ]; then
|
|
|
|
if [ $(id -u) -ne 1000 -a $(id -u) -ne 0 ]; then
|
|
|
|
echo "Changed builder uid/gid... (this may take a while)"
|
2020-09-27 23:36:23 +02:00
|
|
|
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) $CONTAINER_HOME_DIR
|
|
|
|
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) /data
|
|
|
|
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo usermod -u $(id -u) builder
|
|
|
|
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo groupmod -g $(id -g) builder
|
2020-01-23 20:27:06 +01:00
|
|
|
fi
|
2019-02-12 09:23:21 +01:00
|
|
|
fi
|
2016-06-04 00:41:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$#" -eq "0" ]; then
|
2020-09-27 23:36:23 +02:00
|
|
|
$SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME bash
|
2016-06-04 00:41:30 +02:00
|
|
|
else
|
2020-09-27 23:36:23 +02:00
|
|
|
$SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME "$@"
|
2016-06-04 00:41:30 +02:00
|
|
|
fi
|