CI: Don't pin msys2 packages to a specific version at all
[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, bullseye
58 # Typical values for ci_distro=fedora might be 25, rawhide
59 : "${ci_suite:=bullseye}"
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_host" in
91             (i686-w64-mingw32)
92                 $sudo dpkg --add-architecture i386
93                 ;;
94             (x86_64-w64-mingw32)
95                 # assume the host or container is x86_64 already
96                 ;;
97         esac
98
99         $sudo apt-get -qq -y update
100         packages=()
101
102         case "$ci_host" in
103             (i686-w64-mingw32)
104                 packages=(
105                     "${packages[@]}"
106                     binutils-mingw-w64-i686
107                     g++-mingw-w64-i686
108                     wine32 wine
109                 )
110                 ;;
111             (x86_64-w64-mingw32)
112                 packages=(
113                     "${packages[@]}"
114                     binutils-mingw-w64-x86-64
115                     g++-mingw-w64-x86-64
116                     wine64 wine
117                 )
118                 ;;
119         esac
120
121         if [ "$ci_host/$ci_variant/$ci_suite" = "native/production/buster" ]; then
122             packages=(
123                 "${packages[@]}"
124                 qttools5-dev-tools
125                 qt5-default
126             )
127         fi
128
129         packages=(
130             "${packages[@]}"
131             adduser
132             autoconf-archive
133             automake
134             autotools-dev
135             ca-certificates
136             ccache
137             cmake
138             debhelper
139             dh-autoreconf
140             dh-exec
141             docbook-xml
142             docbook-xsl
143             doxygen
144             dpkg-dev
145             ducktype
146             g++
147             gcc
148             gnome-desktop-testing
149             libapparmor-dev
150             libaudit-dev
151             libcap-ng-dev
152             libexpat-dev
153             libglib2.0-dev
154             libselinux1-dev
155             libsystemd-dev
156             libx11-dev
157             python3
158             python3-dbus
159             python3-gi
160             sudo
161             valgrind
162             wget
163             xauth
164             xmlto
165             xsltproc
166             xvfb
167             yelp-tools
168             zstd
169         )
170
171         $sudo apt-get -qq -y --no-install-recommends install "${packages[@]}"
172
173         if [ "$ci_in_docker" = yes ]; then
174             # Add the user that we will use to do the build inside the
175             # Docker container, and let them use sudo
176             adduser --disabled-password --gecos "" user
177             echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nopasswd
178             chmod 0440 /etc/sudoers.d/nopasswd
179         fi
180
181         # Make sure we have a messagebus user, even if the dbus package
182         # isn't installed
183         $sudo adduser --system --quiet --home /nonexistent --no-create-home \
184             --disabled-password --group messagebus
185         ;;
186
187     (*)
188         echo "Don't know how to set up ${ci_distro}" >&2
189         exit 1
190         ;;
191 esac
192
193 if [ "$ci_local_packages" = yes ]; then
194     case "$ci_host" in
195         (*-w64-mingw32)
196             cpu="${ci_host%%-*}"
197             mirror="https://repo.msys2.org/mingw/$cpu"
198             dep_prefix=$(pwd)/${ci_host}-prefix
199             # clean install dir, if present
200             rm -rf ${dep_prefix}
201             install -d "${dep_prefix}"
202             wget -O files.lst ${mirror}
203             sed 's,^<a href=",,g;s,">.*$,,g' files.lst | grep -v "\.db" | grep -v "\.files" | grep ".*zst$" | sort > filenames.lst
204             packages=(
205                 bzip2
206                 expat
207                 gcc-libs
208                 gettext
209                 glib2
210                 iconv
211                 libffi
212                 libiconv
213                 libwinpthread-git
214                 pcre
215                 pcre2
216                 zlib
217             )
218             for pkg in "${packages[@]}" ; do
219                 filename=$(grep -F "mingw-w64-${cpu}-${pkg}-" filenames.lst | tail -1)
220                 if [ -z ${filename} ]; then
221                     echo "could not find filename for package '${pkg}'"
222                     exit 1
223                 fi
224                 # Remove previously downloaded file, which can happen
225                 # when run locally
226                 if [ -f ${filename} ]; then
227                     rm -rf ${filename}
228                 fi
229                 wget ${mirror}/${filename}
230                 tar -C ${dep_prefix} --strip-components=1 -xvf ${filename}
231             done
232
233             # limit access rights
234             if [ "$ci_in_docker" = yes ]; then
235                 chown -R user "${dep_prefix}"
236             fi
237             ;;
238     esac
239 fi
240
241 # vim:set sw=4 sts=4 et: