From bc20ba7e70e0f34bbfdef4ca75ba3ed30db0d817 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Mon, 28 Sep 2020 00:36:23 +0300 Subject: [PATCH] run-docker.sh: if $TERMUX_DOCKER_USE_SUDO is set, run `docker` with sudo Not all system configurations have user being added into `docker` group. --- scripts/run-docker.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/run-docker.sh b/scripts/run-docker.sh index 929ced16f..19460171c 100755 --- a/scripts/run-docker.sh +++ b/scripts/run-docker.sh @@ -15,6 +15,12 @@ fi 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'..." if [ "${GITHUB_EVENT_PATH-x}" != "x" ]; then @@ -24,9 +30,9 @@ else DOCKER_TTY=" --tty" fi -docker start $CONTAINER_NAME >/dev/null 2>&1 || { +$SUDO docker start $CONTAINER_NAME >/dev/null 2>&1 || { echo "Creating new container..." - docker run \ + $SUDO docker run \ --detach \ --name $CONTAINER_NAME \ --volume $REPOROOT:$CONTAINER_HOME_DIR/termux-packages \ @@ -35,16 +41,16 @@ docker start $CONTAINER_NAME >/dev/null 2>&1 || { 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)" - docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) $CONTAINER_HOME_DIR - docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) /data - docker exec $DOCKER_TTY $CONTAINER_NAME sudo usermod -u $(id -u) builder - docker exec $DOCKER_TTY $CONTAINER_NAME sudo groupmod -g $(id -g) builder + $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 fi } if [ "$#" -eq "0" ]; then - docker exec --interactive $DOCKER_TTY $CONTAINER_NAME bash + $SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME bash else - docker exec --interactive $DOCKER_TTY $CONTAINER_NAME "$@" + $SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME "$@" fi