2015-08-18 17:46:18 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-09-21 22:29:00 +02:00
|
|
|
DEFAULT_DOCKCROSS_IMAGE=dockcross/base # DO NOT MOVE THIS LINE (see entrypoint.sh)
|
2016-07-04 06:10:36 +02:00
|
|
|
|
2015-08-18 17:46:18 +02:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# 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
|
2016-07-05 04:27:04 +02:00
|
|
|
Usage: dockcross [options] [--] command [args]
|
2015-08-18 17:46:18 +02:00
|
|
|
|
2016-07-05 04:27:04 +02:00
|
|
|
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:
|
2015-08-18 17:46:18 +02:00
|
|
|
|
|
|
|
update-image
|
|
|
|
update-script
|
|
|
|
update
|
|
|
|
|
2016-07-05 04:27:04 +02:00
|
|
|
For update command help use: $0 help <command>
|
2015-08-18 17:46:18 +02:00
|
|
|
ENDHELP
|
2016-07-05 04:27:04 +02:00
|
|
|
exit 1
|
2015-08-18 17:46:18 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Option processing
|
|
|
|
#
|
2016-09-21 22:31:09 +02:00
|
|
|
special_update_command=''
|
2015-08-18 17:46:18 +02:00
|
|
|
while [[ $# != 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
|
|
|
|
--)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
|
2016-07-05 04:17:22 +02:00
|
|
|
--args|-a)
|
2015-08-18 17:46:18 +02:00
|
|
|
ARG_ARGS="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
2016-07-05 04:17:22 +02:00
|
|
|
--config|-c)
|
2015-08-18 17:46:18 +02:00
|
|
|
ARG_CONFIG="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
2016-07-05 04:17:22 +02:00
|
|
|
--image|-i)
|
2015-08-18 17:46:18 +02:00
|
|
|
ARG_IMAGE="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2016-09-21 22:31:09 +02:00
|
|
|
update|update-image|update-script)
|
|
|
|
special_update_command=$1
|
|
|
|
break
|
|
|
|
;;
|
2015-08-18 17:46:18 +02:00
|
|
|
-*)
|
|
|
|
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
|
2016-07-04 06:10:36 +02:00
|
|
|
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
|
|
|
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
2015-08-18 17:46:18 +02:00
|
|
|
|
|
|
|
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
|
|
|
|
|
|
|
# Set the docker image
|
2016-07-04 06:10:36 +02:00
|
|
|
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
2015-08-18 17:46:18 +02:00
|
|
|
|
2016-09-22 02:25:11 +02:00
|
|
|
# Handle special update command
|
|
|
|
if [ "$special_update_command" != "" ]; then
|
|
|
|
case $special_update_command in
|
|
|
|
|
|
|
|
update)
|
|
|
|
command:update
|
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
|
|
|
|
update-image)
|
|
|
|
command:update-image
|
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
|
|
|
|
update-script)
|
|
|
|
command:update-script
|
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
fi
|
2016-09-21 22:31:09 +02:00
|
|
|
|
2015-08-18 17:46:18 +02:00
|
|
|
# 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
|
2016-07-04 07:28:47 +02:00
|
|
|
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
2015-08-18 17:46:18 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Now, finally, run the command in a container
|
|
|
|
#
|
2016-09-23 17:33:29 +02:00
|
|
|
tty -s && TTY_ARGS=-ti || TTY_ARGS=
|
2016-10-31 04:46:01 +01:00
|
|
|
CONTAINER_NAME=dockcross_$RANDOM
|
2016-10-27 05:24:25 +02:00
|
|
|
docker run $TTY_ARGS --name $CONTAINER_NAME \
|
2016-07-16 07:12:58 +02:00
|
|
|
-v $PWD:/work \
|
2015-08-18 17:46:18 +02:00
|
|
|
$USER_IDS \
|
|
|
|
$FINAL_ARGS \
|
|
|
|
$FINAL_IMAGE "$@"
|
2016-10-27 17:32:22 +02:00
|
|
|
run_exit_code=$?
|
2015-08-18 17:46:18 +02:00
|
|
|
|
2016-10-27 17:32:22 +02:00
|
|
|
# Deleting the container while ignoring error is required because of
|
|
|
|
# https://circleci.com/docs/docker-btrfs-error/.
|
|
|
|
# See issue dockcross/dockcross#50 for more details.
|
2016-10-27 17:19:37 +02:00
|
|
|
docker rm -f $CONTAINER_NAME > /dev/null || true
|
2016-10-27 05:24:25 +02:00
|
|
|
|
2016-10-27 17:32:22 +02:00
|
|
|
exit $run_exit_code
|
|
|
|
|
2015-08-18 17:46:18 +02:00
|
|
|
################################################################################
|
|
|
|
#
|
2016-07-06 03:50:06 +02:00
|
|
|
# This image is not intended to be run manually.
|
2015-08-18 17:46:18 +02:00
|
|
|
#
|
2016-07-06 03:50:06 +02:00
|
|
|
# To create a dockcross helper script for the
|
2016-07-16 05:46:08 +02:00
|
|
|
# dockcross/linux-armv7 image, run:
|
2015-08-18 17:46:18 +02:00
|
|
|
#
|
2016-07-16 05:46:08 +02:00
|
|
|
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
2016-07-06 03:50:06 +02:00
|
|
|
# chmod +x dockcross-linux-armv7
|
2015-08-18 17:46:18 +02:00
|
|
|
#
|
2016-07-06 03:50:06 +02:00
|
|
|
# You may then wish to move the dockcross script to your PATH.
|
2015-08-18 17:46:18 +02:00
|
|
|
#
|
|
|
|
################################################################################
|