ci-install.sh 5.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/bin/bash

# Copyright © 2015-2016 Collabora Ltd.
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set -euo pipefail
set -x

NULL=
29 30 31 32

# ci_distro:
# OS distribution in which we are testing
# Typical values: ubuntu, debian; maybe fedora in future
33
: "${ci_distro:=ubuntu}"
34 35 36 37 38

# ci_docker:
# If non-empty, this is the name of a Docker image. ci-install.sh will
# fetch it with "docker pull" and use it as a base for a new Docker image
# named "ci-image" in which we will do our testing.
39
: "${ci_docker:=}"
40 41 42 43

# ci_host:
# Either "native", or an Autoconf --host argument to cross-compile
# the package
44
: "${ci_host:=native}"
45 46 47 48

# ci_in_docker:
# Used internally by ci-install.sh. If yes, we are inside the Docker image
# (ci_docker is empty in this case).
49
: "${ci_in_docker:=no}"
50 51 52 53 54

# ci_suite:
# OS suite (release, branch) in which we are testing.
# Typical values for ci_distro=debian: sid, jessie
# Typical values for ci_distro=fedora might be 25, rawhide
55 56 57 58 59 60 61 62
: "${ci_suite:=trusty}"

if [ $(id -u) = 0 ]; then
    sudo=
else
    sudo=sudo
fi

63 64 65 66 67 68 69 70 71
if [ -n "$ci_docker" ]; then
    sed \
        -e "s/@ci_distro@/${ci_distro}/" \
        -e "s/@ci_docker@/${ci_docker}/" \
        -e "s/@ci_suite@/${ci_suite}/" \
        < tools/ci-Dockerfile.in > Dockerfile
    exec docker build -t ci-image .
fi

72 73
case "$ci_distro" in
    (debian|ubuntu)
74 75 76 77 78 79 80 81
        # Don't ask questions, just do it
        sudo="$sudo env DEBIAN_FRONTEND=noninteractive"

        # Debian Docker images use httpredir.debian.org but it seems to be
        # unreliable; use a CDN instead
        $sudo sed -i -e 's/httpredir\.debian\.org/deb.debian.org/g' \
            /etc/apt/sources.list

82 83 84
        # travis-ci has a sources list for Chrome which doesn't support i386
        : | $sudo tee /etc/apt/sources.list.d/google-chrome.list

85 86 87 88 89 90 91 92 93 94 95 96
        case "$ci_suite" in
            (trusty)
                # Ubuntu 14.04 didn't have the wine32, wine64 packages
                wine32=wine:i386
                wine64=wine:amd64
                ;;
            (*)
                wine32=wine32
                wine64=wine64
                ;;
        esac

97 98 99 100 101
        case "$ci_host" in
            (i686-w64-mingw32)
                $sudo dpkg --add-architecture i386
                ;;
            (x86_64-w64-mingw32)
102
                # assume the host or container is x86_64 already
103 104
                ;;
        esac
105 106 107

        $sudo apt-get -qq -y update

108 109 110 111 112
        case "$ci_host" in
            (i686-w64-mingw32)
                $sudo apt-get -qq -y install \
                    binutils-mingw-w64-i686 \
                    g++-mingw-w64-i686 \
113
                    $wine32 \
114 115 116 117 118 119
                    ${NULL}
                ;;
            (x86_64-w64-mingw32)
                $sudo apt-get -qq -y install \
                    binutils-mingw-w64-x86-64\
                    g++-mingw-w64-x86-64 \
120
                    $wine64 \
121 122 123
                    ${NULL}
                ;;
        esac
124 125

        $sudo apt-get -qq -y install \
126
            autoconf-archive \
127 128
            automake \
            autotools-dev \
129
            ccache \
130
            cmake \
131 132
            debhelper \
            dh-autoreconf \
133
            dh-exec \
134 135 136 137 138 139 140 141 142 143 144 145 146 147
            doxygen \
            dpkg-dev \
            gnome-desktop-testing \
            libapparmor-dev \
            libaudit-dev \
            libcap-ng-dev \
            libexpat-dev \
            libglib2.0-dev \
            libselinux1-dev \
            libx11-dev \
            python \
            python-dbus \
            python-gi \
            valgrind \
148
            wget \
149 150 151 152 153 154
            xauth \
            xmlto \
            xsltproc \
            xvfb \
            ${NULL}

155 156 157 158 159 160 161 162 163
        case "$ci_suite" in
            (trusty)
                $sudo apt-get -qq -y install libsystemd-daemon-dev
                ;;
            (*)
                $sudo apt-get -qq -y install libsystemd-dev
                ;;
        esac

164
        if [ "$ci_in_docker" = yes ]; then
165 166 167 168 169 170 171 172
            # Add the user that we will use to do the build inside the
            # Docker container, and let them use sudo
            adduser --disabled-password user </dev/null
            apt-get -y install sudo
            echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nopasswd
            chmod 0440 /etc/sudoers.d/nopasswd
        fi

173 174 175
        case "$ci_suite" in
            (trusty|jessie)
                # Ubuntu 14.04's autoconf-archive is too old
176
                wget http://deb.debian.org/debian/pool/main/a/autoconf-archive/autoconf-archive_20160916-1_all.deb
177 178 179 180 181 182 183 184 185 186 187 188 189
                $sudo dpkg -i autoconf-archive_*_all.deb
                rm autoconf-archive_*_all.deb
                ;;
        esac
        ;;

    (*)
        echo "Don't know how to set up ${ci_distro}" >&2
        exit 1
        ;;
esac

# vim:set sw=4 sts=4 et: