mirror of
https://github.com/bensuperpc/dockcross.git
synced 2024-11-09 20:57:26 +01:00
base: Do not add -i -t flags to run command by default
Allow the dockcross script to be used in scripts where a tty is not available.
This commit is contained in:
parent
a3e0d34ac0
commit
f07ca0043c
@ -202,7 +202,7 @@ Examples
|
||||
4. ``dockcross bash -c '$CC test/C/hello.c -o hello'``: Build the *hello.c* file
|
||||
with the compiler identified with the ``CC`` environmental variable in the
|
||||
build environment.
|
||||
5. ``dockcross bash``: Run an interactive shell in the build environment.
|
||||
5. ``dockcross --args -it bash``: Run an interactive shell in the build environment.
|
||||
|
||||
Note that commands are executed verbatim. If any shell processing for
|
||||
environment variable expansion or redirection is required, please use
|
||||
|
@ -153,7 +153,7 @@ fi
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run -i -t --rm \
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
|
@ -1,174 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-x64
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run -i -t --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
Loading…
Reference in New Issue
Block a user