@ -2,11 +2,11 @@
# build and test everything in a fresh docker installation
img = "ubuntu:latest"
repos = ""
keys = ""
envs = ""
dirs = "-v $( pwd ) :/workdir "
packages = ""
repos = ( )
keys = ( )
envs = ( )
dirs = ( "-v $( pwd ) :/workdir " )
packages = ( )
targets = "all check distcheck"
commands = ( )
if test -e ./build-in-docker.conf; then
@ -20,6 +20,7 @@ while test $# -gt 0; do
echo " $0 [OPTIONS] "
echo
echo "OPTIONS:"
echo
echo " -h, --help show this help"
echo " -i, --image <image> use given docker image instead of ${ img } "
echo " -t, --targets targets specify build targets, default: ${ targets } "
@ -28,7 +29,20 @@ while test $# -gt 0; do
echo " -e, --env <var>=<val> set environment variable in docker"
echo " -d, --dir <dir> access given directory read only"
echo " -p, --package <pkg> install extra debian packages"
echo " -x, --exe <command> execute commands as root in docker"
echo " -c, --cmd <command> execute commands as root in docker"
echo
echo " The options -r -k -e -d -p -c can be repeated several times."
echo
echo " The options -r -p -c allow an if-then-else contruct"
echo " depending on the operating system:"
echo " <os>:::<A>:::<B>"
echo " <os>:::<A>"
echo " Read as: On linux type <os> use <A> else use <B>"
echo " That means: If the distributer ID or codename in lsb_release"
echo " matches <os>, then <A> is replaced, else <B> is replaced."
echo " The three colons are for splitting <os> from <A> and <B> part."
echo " E.g.: Install package curl on wheezy and npm on olter systems:"
echo " $0 -p wheezy:::curl:::npm "
echo
echo "EXAMPLE:"
echo
@ -50,21 +64,21 @@ while test $# -gt 0; do
targets = " $1 "
; ;
( -r| --repo) shift;
repos += " $1 "
repos += ( " $1 " )
; ;
( -k| --key) shift;
keys += " $1 "
keys += ( " $1 " )
; ;
( -e| --env) shift;
envs += " -e $1 "
envs += ( "-e $1 " )
; ;
( -d| --dirs) shift;
dirs += " -v $1 : $1 :ro "
dirs += ( "-v $1 : $1 :ro " )
; ;
( -p| --package) shift;
packages += " $1 "
packages += ( " $1 " )
; ;
( -x| --exe ) shift;
( -c| --cmd ) shift;
commands += ( " $1 " )
; ;
( *)
@ -79,28 +93,47 @@ while test $# -gt 0; do
shift
done
function ifthenelse( ) {
arg = " $1 "
shift
cmd = " $* "
if test " ${ arg / : : : / } " = " ${ arg } " ; then
docker exec ${ DOCKER_ID } bash -c " ${ cmd //ARG/ ${ arg } } "
else
os = " ${ arg %% : : : * } "
thenpart = " ${ arg #* : : : } "
if test " ${ thenpart / : : : / } " = " ${ thenpart } " ; then
docker exec ${ DOCKER_ID } bash -c 'os="' $os '"; if test "${os//$(lsb_release -is)/}${os//$(lsb_release -cs)/}" != "${os}${os}"; then ' " ${ cmd //ARG/ ${ thenpart } } " '; fi'
else
elsepart = " ${ thenpart ##* : : : } "
thenpart = " ${ thenpart % : : : * } "
docker exec ${ DOCKER_ID } bash -c 'os="' $os '"; if test "${os//$(lsb_release -is)/}${os//$(lsb_release -cs)/}" != "${os}${os}"; then ' " ${ cmd //ARG/ ${ thenpart } } " '; else ' " ${ cmd //ARG/ ${ elsepart } } " '; fi'
fi
fi
}
set -x
DOCKER_ID = $( docker run -d ${ dirs } ${ envs } -w /workdir $img sleep infinity)
DOCKER_ID = $( docker run -d ${ dirs [@] } ${ envs [@] } -w /workdir $img sleep infinity)
trap " docker rm -f ${ DOCKER_ID } " INT TERM EXIT
docker exec ${ DOCKER_ID } apt-get install -y software-properties-common apt-transport-https dpkg-dev
if test -n " ${ repos } " ; then
for repo in ${ repos } ; do
docker exec ${ DOCKER_ID } apt-add-repository ${ repo }
done
fi
if test -n " ${ keys } " ; then
for key in ${ keys } ; do
wget -O- ${ key } \
| docker exec -i ${ DOCKER_ID } apt-key add -
done
fi
docker exec ${ DOCKER_ID } apt-get update
if test -n " ${ packages } " ; then
docker exec -i ${ DOCKER_ID } apt-get install -y ${ packages }
docker exec ${ DOCKER_ID } apt-get upgrade -y --force-yes
if ! docker exec ${ DOCKER_ID } apt-get install -y --force-yes python-software-properties apt-transport-https dpkg-dev lsb-release; then
docker exec ${ DOCKER_ID } apt-get install -y --force-yes software-properties-common apt-transport-https dpkg-dev lsb-release
fi
for repo in " ${ repos [@] } " ; do
ifthenelse " ${ repo } " "apt-add-repository ARG"
done
for key in " ${ keys [@] } " ; do
wget -O- \
| docker exec -i ${ DOCKER_ID } apt-key add -
done
docker exec ${ DOCKER_ID } apt-get update
for package in " ${ packages [@] } " ; do
ifthenelse " ${ package } " "apt-get install -y --force-yes ARG"
done
for command in " ${ commands [@] } " ; do
docker exec -i ${ DOCKER_ID } ${ command }
ifthenelse " ${ command } " "ARG"
done
docker exec ${ DOCKER_ID } ./resolve-debbuilddeps.sh
docker exec -u $( id -u) ${ DOCKER_ID } svn upgrade || true