diff --git a/build-in-docker.conf b/build-in-docker.conf index 33e9b00..6fb02a1 100644 --- a/build-in-docker.conf +++ b/build-in-docker.conf @@ -1,7 +1,11 @@ -packages+=" npm" -repos+="universe" -commands+=("npm install -g node" "npm install -g cordova") +packages+=("wheezy:::curl:::npm") +packages+=("nodejs") +repos+=("Ubuntu:::universe") +repos+=("wheezy:::'deb http://ftp.is.debian.org/debian wheezy-backports main'") +commands+=("wheezy:::update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100") +commands+=("wheezy:::curl https://www.npmjs.com/install.sh | sh") +commands+=("npm install -g cordova") if test -n "${ANDROID_HOME}"; then - envs+=" -e ANDROID_HOME=${ANDROID_HOME}" - dirs+=" -v ${ANDROID_HOME}:${ANDROID_HOME}:ro" + envs+=("-e ANDROID_HOME=${ANDROID_HOME}") + dirs+=("-v ${ANDROID_HOME}:${ANDROID_HOME}:ro") fi diff --git a/build-in-docker.sh b/build-in-docker.sh index ae9e631..b6a1560 100755 --- a/build-in-docker.sh +++ b/build-in-docker.sh @@ -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 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 = set environment variable in docker" echo " -d, --dir access given directory read only" echo " -p, --package install extra debian packages" - echo " -x, --exe execute commands as root in docker" + echo " -c, --cmd 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 " ::::::" + echo " :::" + echo " Read as: On linux type use else use " + echo " That means: If the distributer ID or codename in lsb_release" + echo " matches , then is replaced, else is replaced." + echo " The three colons are for splitting from and 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 diff --git a/resolve-debbuilddeps.sh b/resolve-debbuilddeps.sh index 5828d1c..6486a4e 100755 --- a/resolve-debbuilddeps.sh +++ b/resolve-debbuilddeps.sh @@ -16,7 +16,11 @@ if test -n "${SCHROOTNAME}"; then SUDO="schroot -c "${SCHROOTNAME}" -u root -d / --" else DO="" - SUDO="sudo" + if grep -q '/docker/' /proc/1/cgroup; then + SUDO="" + else + SUDO="sudo" + fi fi function install() {