|
|
|
@ -6,16 +6,18 @@ myarch=$(dpkg --print-architecture) |
|
|
|
|
if test "${arch}" = "amd64"; then |
|
|
|
|
myarch="amd64|i386" |
|
|
|
|
fi |
|
|
|
|
mode="apt" |
|
|
|
|
mode="deb" |
|
|
|
|
img="ubuntu:latest" |
|
|
|
|
repos=() |
|
|
|
|
keys=() |
|
|
|
|
envs=("-e DEBIAN_FRONTEND=noninteractive" "-e DEBCONF_NONINTERACTIVE_SEEN=true") |
|
|
|
|
dirs=("-v $(pwd):/workdir") |
|
|
|
|
envs=("-e LANG=${LANG}" "-e HOME=/home/$(id -un)" "-e TERM=xterm" "-e DEBIAN_FRONTEND=noninteractive" "-e DEBCONF_NONINTERACTIVE_SEEN=true") |
|
|
|
|
dirs=("-v $(pwd):/workdir" "-v ${HOME}/.gnupg:/home/$(id -un)/.gnupg") |
|
|
|
|
packages=() |
|
|
|
|
targets="all check distcheck" |
|
|
|
|
commands=() |
|
|
|
|
arch=$(dpkg --print-architecture) |
|
|
|
|
arch=$((which dpkg > /dev/null 2> /dev/null && dpkg --print-architecture) || echo amd64) |
|
|
|
|
host= |
|
|
|
|
flags=() |
|
|
|
|
wait=0 |
|
|
|
|
if test -e ./build-in-docker.conf; then |
|
|
|
|
# you can preconfigure the variables in file build-in-docker.conf |
|
|
|
@ -30,10 +32,12 @@ while test $# -gt 0; do |
|
|
|
|
echo "OPTIONS:" |
|
|
|
|
echo |
|
|
|
|
echo " -h, --help show this help" |
|
|
|
|
echo " -m, --mode <type> mode: apt or yum, default: ${mode}" |
|
|
|
|
echo " -m, --mode <type> mode: deb, rpm, win, default: ${mode}" |
|
|
|
|
echo " -i, --image <image> use given docker image instead of ${img}" |
|
|
|
|
echo " -a, --arch <arch> build for given hardware architecture" |
|
|
|
|
echo " -t, --targets targets specify build targets, default: ${targets}" |
|
|
|
|
echo " --host <target-arch> host for cross compiling, e.g. i686-w64-mingw32" |
|
|
|
|
echo " -f, --flag <flag> add flag to ./bootstrap.sh or ./configure" |
|
|
|
|
echo " -r, --repo <url> add given apt repository" |
|
|
|
|
echo " -k, --key <url> add public key from url" |
|
|
|
|
echo " -e, --env <var>=<val> set environment variable in docker" |
|
|
|
@ -43,6 +47,10 @@ while test $# -gt 0; do |
|
|
|
|
echo " -w, --wait on error keep docker container and wait for enter" |
|
|
|
|
echo |
|
|
|
|
echo " The option -i must be after -m, because mode sets a new default image" |
|
|
|
|
echo " The option -m must be after -t, because mode may be auto detected from targets" |
|
|
|
|
echo " The option -m must be after -h, because mode may set a host" |
|
|
|
|
echo " If target is either deb or rpm, mode is set to the same value" |
|
|
|
|
echo " If target is win, host is set to i686-w64-mingw32" |
|
|
|
|
echo |
|
|
|
|
echo " The options -r -k -e -d -p -c can be repeated several times." |
|
|
|
|
echo |
|
|
|
@ -73,8 +81,11 @@ while test $# -gt 0; do |
|
|
|
|
(-m|--mode) shift; |
|
|
|
|
mode="$1" |
|
|
|
|
case "$mode" in |
|
|
|
|
(apt) img="ubuntu:latest";; |
|
|
|
|
(deb|apt) img="ubuntu:latest";; |
|
|
|
|
(rpm|zypper) img="opensuse:latest";; |
|
|
|
|
(yum) img="centos:latest";; |
|
|
|
|
(dnf) img="fedora:latest";; |
|
|
|
|
(win) img="ubuntu:latest"; host="${host:---host=i686-w64-mingw32}";; |
|
|
|
|
(*) |
|
|
|
|
echo "**** ERROR: unknown mode '$1', try --help" 1>&2 |
|
|
|
|
exit 1 |
|
|
|
@ -89,6 +100,17 @@ while test $# -gt 0; do |
|
|
|
|
;; |
|
|
|
|
(-t|--targets) shift; |
|
|
|
|
targets="$1" |
|
|
|
|
if test "$1" = "deb" -o "$1" = "rpm"; then |
|
|
|
|
# set mode to same value |
|
|
|
|
set -- "-m" $@ |
|
|
|
|
continue |
|
|
|
|
fi |
|
|
|
|
;; |
|
|
|
|
(--host) shift; |
|
|
|
|
host="--host=$1" |
|
|
|
|
;; |
|
|
|
|
(-f|--flag) shift; |
|
|
|
|
flags+=("$1") |
|
|
|
|
;; |
|
|
|
|
(-r|--repo) shift; |
|
|
|
|
repos+=("$1") |
|
|
|
@ -149,7 +171,8 @@ function traperror() { |
|
|
|
|
read |
|
|
|
|
fi |
|
|
|
|
echo -n " ... cleanup docker: " |
|
|
|
|
docker rm -f "${DOCKER_ID}" |
|
|
|
|
docker stop "${DOCKER_ID}" || true |
|
|
|
|
docker rm "${DOCKER_ID}" |
|
|
|
|
echo "returning status: $e" |
|
|
|
|
echo "--->" |
|
|
|
|
exit $e |
|
|
|
@ -176,14 +199,14 @@ function ifthenelse() { |
|
|
|
|
os="${arg%%:::*}" |
|
|
|
|
thenpart="${arg#*:::}" |
|
|
|
|
if test "${thenpart/:::/}" = "${thenpart}"; then |
|
|
|
|
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)-$(dpkg --print-architecture)" =~ ${os} ]]; then '"${cmd//ARG/${thenpart}}"'; fi' |
|
|
|
|
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)-$((which dpkg > /dev/null 2> /dev/null && dpkg --print-architecture) || echo amd64)" =~ ${os} ]]; then '"${cmd//ARG/${thenpart}}"'; fi' |
|
|
|
|
else |
|
|
|
|
elsepart="${thenpart##*:::}" |
|
|
|
|
thenpart="${thenpart%:::*}" |
|
|
|
|
if test -n "${thenpart}"; then |
|
|
|
|
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)-$(dpkg --print-architecture)" =~ ${os} ]]; then '"${cmd//ARG/${thenpart}}"'; else '"${cmd//ARG/${elsepart}}"'; fi' |
|
|
|
|
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)-$((which dpkg > /dev/null 2> /dev/null && dpkg --print-architecture) || echo amd64)" =~ ${os} ]]; then '"${cmd//ARG/${thenpart}}"'; else '"${cmd//ARG/${elsepart}}"'; fi' |
|
|
|
|
else |
|
|
|
|
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)-$(dpkg --print-architecture)" =~ ${os} ]]; then true; else '"${cmd//ARG/${elsepart}}"'; fi' |
|
|
|
|
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)-$((which dpkg > /dev/null 2> /dev/null && dpkg --print-architecture) || echo amd64)" =~ ${os} ]]; then true; else '"${cmd//ARG/${elsepart}}"'; fi' |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
@ -192,15 +215,24 @@ function ifthenelse() { |
|
|
|
|
set -x |
|
|
|
|
|
|
|
|
|
docker pull $img |
|
|
|
|
DOCKER_ID=$(docker create ${dirs[@]} ${envs[@]} -e HOME="${HOME}" -w /workdir $img sleep infinity) |
|
|
|
|
DOCKER_ID=$(docker create ${dirs[@]} ${envs[@]} -w /workdir $img sleep infinity) |
|
|
|
|
trap 'traperror '"${DOCKER_ID}"' "$? ${PIPESTATUS[@]}" $LINENO $BASH_LINENO "$BASH_COMMAND" "${FUNCNAME[@]}" "${FUNCTION}"' SIGINT INT TERM EXIT |
|
|
|
|
if ! [[ $arch =~ $myarch ]]; then |
|
|
|
|
docker cp "/usr/bin/qemu-${arch}-static" "${DOCKER_ID}:/usr/bin/qemu-${arch}-static" |
|
|
|
|
fi |
|
|
|
|
docker start "${DOCKER_ID}" |
|
|
|
|
docker exec ${DOCKER_ID} useradd -u$(id -u) -m -d"${HOME}" $(id -un) |
|
|
|
|
if ! docker exec ${DOCKER_ID} getent group $(id -g) > /dev/null 2>&1; then |
|
|
|
|
docker exec ${DOCKER_ID} groupadd -g $(id -g) $(id -gn) |
|
|
|
|
fi |
|
|
|
|
if ! docker exec ${DOCKER_ID} getent passwd $(id -u) > /dev/null 2>&1; then |
|
|
|
|
docker exec ${DOCKER_ID} useradd -m -u $(id -u) -g $(id -g) -d"${HOME}" $(id -un) |
|
|
|
|
fi |
|
|
|
|
case $mode in |
|
|
|
|
(apt) |
|
|
|
|
(deb|apt) |
|
|
|
|
if [[ "${img}" =~ "ubuntu" ]]; then |
|
|
|
|
docker exec ${DOCKER_ID} locale-gen ${LANG} |
|
|
|
|
docker exec ${DOCKER_ID} update-locale LANG=${LANG} |
|
|
|
|
fi |
|
|
|
|
OPTIONS='-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew -y --force-yes --no-install-suggests --no-install-recommends' |
|
|
|
|
for f in 'libpam-systemd:amd64' 'policykit*' 'colord'; do |
|
|
|
|
docker exec ${DOCKER_ID} bash -c "echo 'Package: $f' >> /etc/apt/preferences" |
|
|
|
@ -228,8 +260,7 @@ case $mode in |
|
|
|
|
done |
|
|
|
|
docker exec ${DOCKER_ID} ./resolve-debbuilddeps.sh |
|
|
|
|
;; |
|
|
|
|
(yum) |
|
|
|
|
./bootstrap.sh -t dist |
|
|
|
|
(rpm|yum|dnf|zypper|urpmi) |
|
|
|
|
if [[ "$img" =~ "centos" ]]; then |
|
|
|
|
docker exec ${DOCKER_ID} yum install -y redhat-lsb |
|
|
|
|
docker exec -i ${DOCKER_ID} bash -c 'cat > /etc/yum.repos.d/wandisco-svn.repo' <<EOF |
|
|
|
@ -242,10 +273,29 @@ enabled=1 |
|
|
|
|
gpgcheck=0 |
|
|
|
|
EOF |
|
|
|
|
fi |
|
|
|
|
docker exec ${DOCKER_ID} yum install -y rpm-build |
|
|
|
|
docker exec ${DOCKER_ID} groupadd -g $(id -g) build |
|
|
|
|
docker exec ${DOCKER_ID} useradd -g $(id -g) -u $(id -u) build |
|
|
|
|
docker exec ${DOCKER_ID} ./resolve-rpmbuilddeps.sh || true |
|
|
|
|
INSTALL_TOOL=$((docker exec ${DOCKER_ID} test -x /usr/bin/zypper && echo zypper install -y) || (docker exec ${DOCKER_ID} test -x /usr/bin/dnf && echo dnf install -y) || (docker exec ${DOCKER_ID} test -x /usr/bin/yum && echo yum install -y) || (docker exec ${DOCKER_ID} test -x /usr/sbin/urpmi && echo urpmi --auto)) |
|
|
|
|
docker exec ${DOCKER_ID} ${INSTALL_TOOL} rpm-build automake libtool subversion gcc-c++ pkgconfig wget /usr/bin/lsb_release |
|
|
|
|
i=0 |
|
|
|
|
for key in "${keys[@]}"; do |
|
|
|
|
wget -Orpm-key "$key" |
|
|
|
|
docker exec -i ${DOCKER_ID} rpm --import rpm-key |
|
|
|
|
rm rpm-key |
|
|
|
|
done |
|
|
|
|
for repo in "${repos[@]}"; do |
|
|
|
|
INSTALL_REPO=$((docker exec ${DOCKER_ID} test -x /usr/bin/zypper && echo zypper ar) || (docker exec ${DOCKER_ID} test -x /usr/bin/dnf && echo dnf config-manager --add-repo) || (docker exec ${DOCKER_ID} test -x /usr/bin/yum && echo wget -O/etc/yum.repos.d/additional$i.repo) || (docker exec ${DOCKER_ID} test -x /usr/sbin/urpmi && echo true)) |
|
|
|
|
ifthenelse "${repo}" "${INSTALL_REPO} ARG" |
|
|
|
|
((++i)) |
|
|
|
|
done |
|
|
|
|
docker exec ${DOCKER_ID} ./resolve-rpmbuilddeps.sh |
|
|
|
|
;; |
|
|
|
|
(win) |
|
|
|
|
if [[ "${img}" =~ "ubuntu" ]]; then |
|
|
|
|
docker exec ${DOCKER_ID} locale-gen ${LANG} |
|
|
|
|
docker exec ${DOCKER_ID} update-locale LANG=${LANG} |
|
|
|
|
fi |
|
|
|
|
docker exec ${DOCKER_ID} apt-get update ${OPTIONS} |
|
|
|
|
docker exec ${DOCKER_ID} apt-get install -y mingw-w64 |
|
|
|
|
docker exec ${DOCKER_ID} ./resolve-debbuilddeps.sh |
|
|
|
|
;; |
|
|
|
|
esac |
|
|
|
|
docker exec -u $(id -u):$(id -g) ${DOCKER_ID} ./bootstrap.sh -t "${targets}" |
|
|
|
|
docker exec -u $(id -u):$(id -g) ${DOCKER_ID} ./bootstrap.sh -t "${targets}" ${host} ${flags[@]} |
|
|
|
|