2d3d3af0955959765f395454d170867746ccdf1d
[platform/upstream/dbus.git] / tools / ci-install.sh
1 #!/bin/bash
2
3 # Copyright © 2015-2016 Collabora Ltd.
4 #
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation files
7 # (the "Software"), to deal in the Software without restriction,
8 # including without limitation the rights to use, copy, modify, merge,
9 # publish, distribute, sublicense, and/or sell copies of the Software,
10 # and to permit persons to whom the Software is furnished to do so,
11 # subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE.
24
25 set -euo pipefail
26 set -x
27
28 NULL=
29
30 # ci_distro:
31 # OS distribution in which we are testing
32 # Typical values: ubuntu, debian; maybe fedora in future
33 : "${ci_distro:=ubuntu}"
34
35 # ci_docker:
36 # If non-empty, this is the name of a Docker image. ci-install.sh will
37 # fetch it with "docker pull" and use it as a base for a new Docker image
38 # named "ci-image" in which we will do our testing.
39 : "${ci_docker:=}"
40
41 # ci_host:
42 # Either "native", or an Autoconf --host argument to cross-compile
43 # the package
44 : "${ci_host:=native}"
45
46 # ci_in_docker:
47 # Used internally by ci-install.sh. If yes, we are inside the Docker image
48 # (ci_docker is empty in this case).
49 : "${ci_in_docker:=no}"
50
51 # ci_suite:
52 # OS suite (release, branch) in which we are testing.
53 # Typical values for ci_distro=debian: sid, jessie
54 # Typical values for ci_distro=fedora might be 25, rawhide
55 : "${ci_suite:=xenial}"
56
57 # ci_variant:
58 # One of debug, reduced, legacy, production
59 : "${ci_variant:=production}"
60
61 if [ $(id -u) = 0 ]; then
62     sudo=
63 else
64     sudo=sudo
65 fi
66
67 if [ -n "$ci_docker" ]; then
68     sed \
69         -e "s/@ci_distro@/${ci_distro}/" \
70         -e "s/@ci_docker@/${ci_docker}/" \
71         -e "s/@ci_suite@/${ci_suite}/" \
72         < tools/ci-Dockerfile.in > Dockerfile
73     exec docker build -t ci-image .
74 fi
75
76 case "$ci_distro" in
77     (debian|ubuntu)
78         # Don't ask questions, just do it
79         sudo="$sudo env DEBIAN_FRONTEND=noninteractive"
80
81         # Debian Docker images use httpredir.debian.org but it seems to be
82         # unreliable; use a CDN instead
83         $sudo sed -i -e 's/httpredir\.debian\.org/deb.debian.org/g' \
84             /etc/apt/sources.list
85
86         case "$ci_suite" in
87             (xenial)
88                 # Ubuntu 16.04 didn't have the wine32, wine64 packages
89                 wine32=wine:i386
90                 wine64=wine:amd64
91                 ;;
92             (*)
93                 wine32=wine32
94                 wine64=wine64
95                 ;;
96         esac
97
98         case "$ci_suite" in
99             (trusty)
100                 # Ubuntu 14.04 didn't have the wine32, wine64 packages
101                 wine32=wine:i386
102                 wine64=wine:amd64
103                 ;;
104             (*)
105                 wine32=wine32
106                 wine64=wine64
107                 ;;
108         esac
109
110         case "$ci_host" in
111             (i686-w64-mingw32)
112                 $sudo dpkg --add-architecture i386
113                 ;;
114             (x86_64-w64-mingw32)
115                 # assume the host or container is x86_64 already
116                 ;;
117         esac
118
119         $sudo apt-get -qq -y update
120         packages=()
121
122         case "$ci_host" in
123             (i686-w64-mingw32)
124                 packages=(
125                     "${packages[@]}"
126                     binutils-mingw-w64-i686
127                     g++-mingw-w64-i686
128                     $wine32 wine
129                 )
130                 ;;
131             (x86_64-w64-mingw32)
132                 packages=(
133                     "${packages[@]}"
134                     binutils-mingw-w64-x86-64
135                     g++-mingw-w64-x86-64
136                     $wine64 wine
137                 )
138                 ;;
139         esac
140
141         if [ "$ci_host/$ci_variant/$ci_suite" = "native/production/buster" ]; then
142             packages=(
143                 "${packages[@]}"
144                 qttools5-dev-tools
145                 qt5-default
146             )
147         fi
148
149         packages=(
150             "${packages[@]}"
151             adduser
152             autoconf-archive
153             automake
154             autotools-dev
155             ccache
156             cmake
157             debhelper
158             dh-autoreconf
159             dh-exec
160             docbook-xml
161             docbook-xsl
162             doxygen
163             dpkg-dev
164             g++
165             gcc
166             gnome-desktop-testing
167             libapparmor-dev
168             libaudit-dev
169             libcap-ng-dev
170             libexpat-dev
171             libglib2.0-dev
172             libselinux1-dev
173             libsystemd-dev
174             libx11-dev
175             python
176             python-dbus
177             python-gi
178             sudo
179             valgrind
180             wget
181             xauth
182             xmlto
183             xsltproc
184             xvfb
185         )
186
187         case "$ci_suite" in
188             (stretch)
189                 # Debian 9 'stretch' didn't have the ducktype package
190                 ;;
191
192             (*)
193                 # assume Ubuntu 18.04 'bionic', Debian 10 'buster' or newer
194                 packages=(
195                     "${packages[@]}"
196                     ducktype yelp-tools
197                 )
198                 ;;
199         esac
200
201         $sudo apt-get -qq -y --no-install-recommends install "${packages[@]}"
202
203         if [ "$ci_in_docker" = yes ]; then
204             # Add the user that we will use to do the build inside the
205             # Docker container, and let them use sudo
206             adduser --disabled-password --gecos "" user
207             echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nopasswd
208             chmod 0440 /etc/sudoers.d/nopasswd
209         fi
210
211         # manual package setup
212         case "$ci_suite" in
213             (jessie|xenial)
214                 # autoconf-archive in Debian 8 and Ubuntu 16.04 is too old,
215                 # use the one from Debian 9 instead
216                 wget http://deb.debian.org/debian/pool/main/a/autoconf-archive/autoconf-archive_20160916-1_all.deb
217                 $sudo dpkg -i autoconf-archive_*_all.deb
218                 rm autoconf-archive_*_all.deb
219                 ;;
220         esac
221
222         case "$ci_host" in
223             (*-w64-mingw32)
224                 mirror=http://repo.msys2.org/mingw/${ci_host%%-*}
225                 if [ "${ci_host%%-*}" = i686 ]; then
226                     mingw="$(pwd)/mingw32"
227                 else
228                     mingw="$(pwd)/mingw64"
229                 fi
230                 install -d "${mingw}"
231                 for pkg in \
232                     bzip2-1.0.8-1 \
233                     expat-2.2.9-1 \
234                     gcc-libs-9.3.0-2 \
235                     gettext-0.19.8.1-8 \
236                     glib2-2.64.2-1 \
237                     iconv-1.16-1 \
238                     libffi-3.3-1 \
239                     libiconv-1.16-1 \
240                     libwinpthread-git-8.0.0.5814.9dbf4cc1-1 \
241                     pcre-8.44-1 \
242                     zlib-1.2.11-7 \
243                 ; do
244                     wget ${mirror}/mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.xz
245                     tar -xvf mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.xz
246                 done
247
248                 # limit access rights
249                 if [ "$ci_in_docker" = yes ]; then
250                     chown -R user "${mingw}"
251                 fi
252                 ;;
253         esac
254
255         # Make sure we have a messagebus user, even if the dbus package
256         # isn't installed
257         $sudo adduser --system --quiet --home /nonexistent --no-create-home \
258             --disabled-password --group messagebus
259         ;;
260
261     (*)
262         echo "Don't know how to set up ${ci_distro}" >&2
263         exit 1
264         ;;
265 esac
266
267 # vim:set sw=4 sts=4 et: