termux-packages/scripts/run-docker.sh

60 lines
1.6 KiB
Bash
Raw Normal View History

2016-05-28 00:24:50 +02:00
#!/bin/sh
set -e -u
CONTAINER_HOME_DIR=/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
SEC_OPT=""
else
REPOROOT="$(dirname $(readlink -f $0))/../"
SEC_OPT=" --security-opt seccomp=$REPOROOT/scripts/profile.json"
fi
: ${TERMUX_BUILDER_IMAGE_NAME:=termux/package-builder}
: ${CONTAINER_NAME:=termux-package-builder}
2016-05-28 00:24:50 +02:00
USER=builder
if [ -n "${TERMUX_DOCKER_USE_SUDO-}" ]; then
SUDO="sudo"
else
SUDO=""
fi
echo "Running container '$CONTAINER_NAME' from image '$TERMUX_BUILDER_IMAGE_NAME'..."
# Check whether attached to tty and adjust docker flags accordingly.
if [ -t 1 ]; then
DOCKER_TTY=" --tty"
else
DOCKER_TTY=""
fi
$SUDO docker start $CONTAINER_NAME >/dev/null 2>&1 || {
echo "Creating new container..."
$SUDO docker run \
2019-02-21 02:35:57 +01:00
--detach \
--name $CONTAINER_NAME \
--volume $REPOROOT:$CONTAINER_HOME_DIR/termux-packages \
$SEC_OPT \
2019-02-21 02:35:57 +01:00
--tty \
$TERMUX_BUILDER_IMAGE_NAME
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)"
$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
fi
2019-02-12 09:23:21 +01:00
fi
}
if [ "$#" -eq "0" ]; then
$SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME bash
else
$SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME "$@"
fi