CI: Install ci-certificates
[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_local_packages:
52 # prefer local packages instead of distribution
53 : "${ci_local_packages:=yes}"
54
55 # ci_suite:
56 # OS suite (release, branch) in which we are testing.
57 # Typical values for ci_distro=debian: sid, jessie
58 # Typical values for ci_distro=fedora might be 25, rawhide
59 : "${ci_suite:=xenial}"
60
61 # ci_variant:
62 # One of debug, reduced, legacy, production
63 : "${ci_variant:=production}"
64
65 if [ $(id -u) = 0 ]; then
66     sudo=
67 else
68     sudo=sudo
69 fi
70
71 if [ -n "$ci_docker" ]; then
72     sed \
73         -e "s/@ci_distro@/${ci_distro}/" \
74         -e "s/@ci_docker@/${ci_docker}/" \
75         -e "s/@ci_suite@/${ci_suite}/" \
76         < tools/ci-Dockerfile.in > Dockerfile
77     exec docker build -t ci-image .
78 fi
79
80 case "$ci_distro" in
81     (debian|ubuntu)
82         # Don't ask questions, just do it
83         sudo="$sudo env DEBIAN_FRONTEND=noninteractive"
84
85         # Debian Docker images use httpredir.debian.org but it seems to be
86         # unreliable; use a CDN instead
87         $sudo sed -i -e 's/httpredir\.debian\.org/deb.debian.org/g' \
88             /etc/apt/sources.list
89
90         case "$ci_suite" in
91             (xenial)
92                 # Ubuntu 16.04 didn't have the wine32, wine64 packages
93                 wine32=wine:i386
94                 wine64=wine:amd64
95                 ;;
96             (*)
97                 wine32=wine32
98                 wine64=wine64
99                 ;;
100         esac
101
102         case "$ci_suite" in
103             (trusty)
104                 # Ubuntu 14.04 didn't have the wine32, wine64 packages
105                 wine32=wine:i386
106                 wine64=wine:amd64
107                 ;;
108             (*)
109                 wine32=wine32
110                 wine64=wine64
111                 ;;
112         esac
113
114         case "$ci_host" in
115             (i686-w64-mingw32)
116                 $sudo dpkg --add-architecture i386
117                 ;;
118             (x86_64-w64-mingw32)
119                 # assume the host or container is x86_64 already
120                 ;;
121         esac
122
123         $sudo apt-get -qq -y update
124         packages=()
125
126         case "$ci_host" in
127             (i686-w64-mingw32)
128                 packages=(
129                     "${packages[@]}"
130                     binutils-mingw-w64-i686
131                     g++-mingw-w64-i686
132                     $wine32 wine
133                 )
134                 ;;
135             (x86_64-w64-mingw32)
136                 packages=(
137                     "${packages[@]}"
138                     binutils-mingw-w64-x86-64
139                     g++-mingw-w64-x86-64
140                     $wine64 wine
141                 )
142                 ;;
143         esac
144
145         if [ "$ci_host/$ci_variant/$ci_suite" = "native/production/buster" ]; then
146             packages=(
147                 "${packages[@]}"
148                 qttools5-dev-tools
149                 qt5-default
150             )
151         fi
152
153         packages=(
154             "${packages[@]}"
155             adduser
156             autoconf-archive
157             automake
158             autotools-dev
159             ca-certificates
160             ccache
161             cmake
162             debhelper
163             dh-autoreconf
164             dh-exec
165             docbook-xml
166             docbook-xsl
167             doxygen
168             dpkg-dev
169             g++
170             gcc
171             gnome-desktop-testing
172             libapparmor-dev
173             libaudit-dev
174             libcap-ng-dev
175             libexpat-dev
176             libglib2.0-dev
177             libselinux1-dev
178             libsystemd-dev
179             libx11-dev
180             python
181             python-dbus
182             python-gi
183             sudo
184             valgrind
185             wget
186             xauth
187             xmlto
188             xsltproc
189             xvfb
190             zstd
191         )
192
193         case "$ci_suite" in
194             (stretch)
195                 # Debian 9 'stretch' didn't have the ducktype package
196                 ;;
197
198             (*)
199                 # assume Ubuntu 18.04 'bionic', Debian 10 'buster' or newer
200                 packages=(
201                     "${packages[@]}"
202                     ducktype yelp-tools
203                 )
204                 ;;
205         esac
206
207         $sudo apt-get -qq -y --no-install-recommends install "${packages[@]}"
208
209         if [ "$ci_in_docker" = yes ]; then
210             # Add the user that we will use to do the build inside the
211             # Docker container, and let them use sudo
212             adduser --disabled-password --gecos "" user
213             echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nopasswd
214             chmod 0440 /etc/sudoers.d/nopasswd
215         fi
216
217         # manual package setup
218         case "$ci_suite" in
219             (jessie|xenial)
220                 # autoconf-archive in Debian 8 and Ubuntu 16.04 is too old,
221                 # use the one from Debian 9 instead
222                 wget http://deb.debian.org/debian/pool/main/a/autoconf-archive/autoconf-archive_20160916-1_all.deb
223                 $sudo dpkg -i autoconf-archive_*_all.deb
224                 rm autoconf-archive_*_all.deb
225                 ;;
226         esac
227
228         # Make sure we have a messagebus user, even if the dbus package
229         # isn't installed
230         $sudo adduser --system --quiet --home /nonexistent --no-create-home \
231             --disabled-password --group messagebus
232         ;;
233
234     (*)
235         echo "Don't know how to set up ${ci_distro}" >&2
236         exit 1
237         ;;
238 esac
239
240 if [ "$ci_local_packages" = yes ]; then
241     case "$ci_host" in
242         (*-w64-mingw32)
243             mirror=http://repo.msys2.org/mingw/${ci_host%%-*}
244             dep_prefix=$(pwd)/${ci_host}-prefix
245             install -d "${dep_prefix}"
246             packages=(
247                 bzip2-1.0.8-2
248                 expat-2.2.10-1
249                 gcc-libs-10.2.0-6
250                 gettext-0.19.8.1-10
251                 glib2-2.66.4-1
252                 iconv-1.16-2
253                 libffi-3.3-2
254                 libiconv-1.16-2
255                 libwinpthread-git-8.0.0.5906.c9a21571-1
256                 pcre-8.44-2
257                 zlib-1.2.11-8
258             )
259             for pkg in "${packages[@]}" ; do
260                 wget ${mirror}/mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.zst
261                 tar -C ${dep_prefix} --strip-components=1 -xvf mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.zst
262             done
263
264             # limit access rights
265             if [ "$ci_in_docker" = yes ]; then
266                 chown -R user "${dep_prefix}"
267             fi
268             ;;
269     esac
270 fi
271
272 # vim:set sw=4 sts=4 et: