e297fb13f2fc4afa89872d4d907f0a8747d0b034
[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     "$@"
48
49   if [ -n "$HOST" ]; then
50     apt-get install -y crossbuild-essential-"$HOST" qemu-user
51   else
52     linux_openssl3
53   fi
54 }
55
56 deps_linux_debian() {
57   export DEBIAN_FRONTEND=noninteractive
58
59   apt-get update
60   apt-get upgrade -y
61   apt-get install -y git pkgconf sudo texinfo ninja-build
62
63   HOST=${HOST:-}
64   if [ "$HOST" = mingw ]; then
65     deps_linux_debian_mingw "$@"
66   else
67     deps_linux_debian_linux "$@"
68   fi
69
70   if [ -n "$SKIP_MESON" ]; then
71     return
72   fi
73
74   . /etc/os-release
75
76   # Debian Buster ships an old version of meson (0.49).
77   # MinGW cross-compilation requires something newer than 0.55 that ships in Bullseye,
78   # or it fails when looking for dependencies in the OpenSSL wrap.
79   if [ "${ID:-}/${VERSION_CODENAME:-}" = debian/buster ] || [ "$HOST" = mingw ]; then
80     apt-get install -y python3 python3-pip ninja-build
81     pip3 install meson
82   else
83     apt-get install -y meson
84   fi
85 }
86
87 deps_linux_rhel() {
88   yum upgrade -y
89
90   if [ "$ID" != fedora ]; then
91     yum install -y epel-release
92
93     if type dnf; then
94       dnf install -y 'dnf-command(config-manager)'
95       dnf config-manager --enable powertools || true
96       dnf config-manager --enable crb || true
97     fi
98   fi
99
100   yum install -y \
101     git binutils make ninja-build pkgconf gcc sudo texinfo-tex systemd perl-IPC-Cmd \
102     lzo-devel zlib-devel lz4-devel ncurses-devel readline-devel libgcrypt-devel "$@"
103
104   if [ -z "$SKIP_MESON" ]; then
105     yum install -y meson
106   fi
107
108   if yum info openssl11-devel; then
109     yum install -y openssl11-devel
110   else
111     dnf install -y openssl-devel
112   fi
113
114   if yum info miniupnpc-devel; then
115     yum install -y miniupnpc-devel
116   fi
117 }
118
119 linux_openssl3() {
120   if [ -n "$SKIP_OPENSSL3" ]; then
121     echo >&2 "skipping openssl3 installation in this job"
122     return
123   fi
124
125   src=/usr/local/src/openssl
126   ssl3=/opt/ssl3
127
128   mkdir -p $src
129
130   git clone --depth 1 --branch openssl-3.0.2 https://github.com/openssl/openssl $src
131   cd $src
132
133   ./Configure --prefix=$ssl3 --openssldir=$ssl3
134   make -j"$(nproc)"
135   make install_sw
136
137   if [ -f /etc/ld.so.conf ]; then
138     echo $ssl3/lib64 >>/etc/ld.so.conf
139     ldconfig -v
140   else
141     ldconfig -v $ssl3/lib64
142   fi
143
144   cd -
145 }
146
147 deps_linux() {
148   . /etc/os-release
149
150   case "$ID" in
151   alpine)
152     deps_linux_alpine "$@"
153     ;;
154
155   debian | ubuntu)
156     deps_linux_debian "$@"
157     ;;
158
159   fedora)
160     deps_linux_rhel "$@"
161     ;;
162
163   centos | almalinux)
164     deps_linux_rhel "$@"
165
166     if [ "${PLATFORM_ID:-}" != platform:el9 ]; then
167       linux_openssl3
168     fi
169     ;;
170
171   *) exit 1 ;;
172   esac
173 }
174
175 deps_macos() {
176   brew install lzo lz4 miniupnpc libgcrypt openssl "$@"
177
178   if [ -z "$SKIP_MESON" ]; then
179     brew install meson
180   fi
181 }
182
183 case "$(uname -s)" in
184 Linux) deps_linux "$@" ;;
185 Darwin) deps_macos "$@" ;;
186 *) exit 1 ;;
187 esac