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