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