17b49bbc523bd5f7a78f67de4a32a2bab79c9b59
[tinc] / .ci / deps.sh
1 #!/bin/sh
2
3 set -eu
4
5 SKIP_OPENSSL3="${SKIP_OPENSSL3:-}"
6 SKIP_MESON="${SKIP_MESON:-}"
7
8 deps_linux_alpine() {
9   apk upgrade
10
11   apk add \
12     git binutils ninja pkgconf gcc linux-headers shadow sudo libgcrypt-dev texinfo gzip \
13     openssl-dev zlib-dev lzo-dev ncurses-dev readline-dev musl-dev lz4-dev vde2-dev cmocka-dev
14
15   if [ -z "$SKIP_MESON" ]; then
16     apk add meson
17   fi
18 }
19
20 deps_linux_debian_mingw() {
21   apt-get install -y \
22     mingw-w64 mingw-w64-tools \
23     wine wine-binfmt \
24     libgcrypt-mingw-w64-dev \
25     "$@"
26 }
27
28 deps_linux_debian_linux() {
29   if [ -n "$HOST" ]; then
30     dpkg --add-architecture "$HOST"
31   fi
32
33   apt-get update
34
35   apt-get install -y \
36     binutils make gcc \
37     zlib1g-dev:"$HOST" \
38     libssl-dev:"$HOST" \
39     liblzo2-dev:"$HOST" \
40     liblz4-dev:"$HOST" \
41     libncurses-dev:"$HOST" \
42     libreadline-dev:"$HOST" \
43     libgcrypt-dev:"$HOST" \
44     libminiupnpc-dev:"$HOST" \
45     libvdeplug-dev:"$HOST" \
46     libcmocka-dev:"$HOST" \
47     libsystemd-dev:"$HOST" \
48     "$@"
49
50   if [ -n "$HOST" ]; then
51     apt-get install -y crossbuild-essential-"$HOST" qemu-user
52   else
53     linux_openssl3
54   fi
55 }
56
57 deps_linux_debian() {
58   export DEBIAN_FRONTEND=noninteractive
59
60   apt-get update
61   apt-get upgrade -y
62   apt-get install -y git pkgconf sudo texinfo ninja-build
63
64   HOST=${HOST:-}
65   if [ "$HOST" = mingw ]; then
66     deps_linux_debian_mingw "$@"
67   else
68     deps_linux_debian_linux "$@"
69   fi
70
71   if [ -n "$SKIP_MESON" ]; then
72     return
73   fi
74
75   . /etc/os-release
76
77   # Debian Buster ships an old version of meson (0.49).
78   # MinGW cross-compilation requires something newer than 0.55 that ships in Bullseye,
79   # or it fails when looking for dependencies in the OpenSSL wrap.
80   if [ "${ID:-}/${VERSION_CODENAME:-}" = debian/buster ] || [ "$HOST" = mingw ]; then
81     apt-get install -y python3 python3-pip ninja-build
82     pip3 install meson
83   else
84     apt-get install -y meson
85   fi
86 }
87
88 deps_linux_rhel() {
89   yum upgrade -y
90
91   if [ "$ID" != fedora ]; then
92     yum install -y epel-release
93
94     if type dnf; then
95       dnf install -y 'dnf-command(config-manager)'
96       dnf config-manager --enable powertools || true
97       dnf config-manager --enable crb || true
98     fi
99   fi
100
101   yum install -y \
102     git binutils make ninja-build pkgconf gcc sudo texinfo-tex systemd perl-IPC-Cmd \
103     lzo-devel zlib-devel lz4-devel ncurses-devel readline-devel libgcrypt-devel systemd-devel "$@"
104
105   if [ -z "$SKIP_MESON" ]; then
106     yum install -y meson
107   fi
108
109   if yum info openssl11-devel; then
110     yum install -y openssl11-devel
111   else
112     dnf install -y openssl-devel
113   fi
114
115   if yum info miniupnpc-devel; then
116     yum install -y miniupnpc-devel
117   fi
118 }
119
120 linux_openssl3() {
121   if [ -n "$SKIP_OPENSSL3" ]; then
122     echo >&2 "skipping openssl3 installation in this job"
123     return
124   fi
125
126   src=/usr/local/src/openssl
127   ssl3=/opt/ssl3
128
129   mkdir -p $src
130
131   git clone --depth 1 --branch openssl-3.0.2 https://github.com/openssl/openssl $src
132   cd $src
133
134   ./Configure --prefix=$ssl3 --openssldir=$ssl3
135   make -j"$(nproc)"
136   make install_sw
137
138   if [ -f /etc/ld.so.conf ]; then
139     echo $ssl3/lib64 >>/etc/ld.so.conf
140     ldconfig -v
141   else
142     ldconfig -v $ssl3/lib64
143   fi
144
145   cd -
146 }
147
148 deps_linux() {
149   . /etc/os-release
150
151   case "$ID" in
152   alpine)
153     deps_linux_alpine "$@"
154     ;;
155
156   debian | ubuntu)
157     deps_linux_debian "$@"
158     ;;
159
160   fedora)
161     deps_linux_rhel "$@"
162     ;;
163
164   centos | almalinux)
165     deps_linux_rhel "$@"
166
167     if [ "${PLATFORM_ID:-}" != platform:el9 ]; then
168       linux_openssl3
169     fi
170     ;;
171
172   *) exit 1 ;;
173   esac
174 }
175
176 deps_macos() {
177   brew install lzo lz4 miniupnpc libgcrypt openssl "$@"
178
179   if [ -z "$SKIP_MESON" ]; then
180     brew install meson
181   fi
182 }
183
184 case "$(uname -s)" in
185 Linux) deps_linux "$@" ;;
186 Darwin) deps_macos "$@" ;;
187 *) exit 1 ;;
188 esac