1#!/bin/bash 2set -eu -o pipefail 3 4quote() { 5 local arg 6 for arg in "$@"; do 7 printf "'" 8 printf "%s" "$arg" | sed -e "s/'/'\\\\''/g" 9 printf "' " 10 done 11} 12 13readonly grpc_java_dir="$(dirname "$(readlink -f "$0")")/.." 14if [[ -t 0 ]]; then 15 DOCKER_ARGS="-it" 16else 17 # The input device on kokoro is not a TTY, so -it does not work. 18 DOCKER_ARGS= 19fi 20# Use a trap function to fix file permissions upon exit, without affecting 21# the original exit code. $DOCKER_ARGS can not be quoted, otherwise it becomes a '' which confuses 22# docker. 23exec docker run $DOCKER_ARGS --rm=true -v "${grpc_java_dir}":/grpc-java -w /grpc-java \ 24 protoc-artifacts \ 25 bash -c "function fixFiles() { chown -R $(id -u):$(id -g) /grpc-java; }; trap fixFiles EXIT; $(quote "$@")" 26