1#!/usr/bin/env bash
2
3set -ex
4
5# install the wasm toolchain
6which rustup > /dev/null 2>&1 || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
7
8# if sudo is not installed, define an empty alias
9maysudo=$(command -v sudo || command -v doas || true)
10
11# Ubuntu, Debian, etc.
12# https://packages.ubuntu.com/
13apt=$(command -v apt-get || true)
14if [[ -n $apt ]]; then
15 deps=(
16 gcc
17 g++
18 libasound2-dev
19 libfontconfig-dev
20 libwayland-dev
21 libxkbcommon-x11-dev
22 libssl-dev
23 libzstd-dev
24 libvulkan1
25 libgit2-dev
26 make
27 clang
28 mold
29 )
30 $maysudo "$apt" install -y "${deps[@]}"
31 exit 0
32fi
33
34# Fedora, CentOS, RHEL, etc.
35# https://packages.fedoraproject.org/
36dnf=$(command -v dnf || true)
37if [[ -n $dnf ]]; then
38 deps=(
39 gcc
40 g++
41 clang
42 mold
43 alsa-lib-devel
44 fontconfig-devel
45 wayland-devel
46 libxkbcommon-x11-devel
47 openssl-devel
48 libzstd-devel
49 # Perl dependencies are needed for openssl-sys crate see https://docs.rs/openssl/latest/openssl/
50 perl-FindBin
51 perl-IPC-Cmd
52 perl-File-Compare
53 perl-File-Copy
54 vulkan-loader
55 )
56
57 # libxkbcommon-x11-devel is in the crb repo on RHEL and CentOS, not needed for Fedora
58 if ! grep -q "Fedora" /etc/redhat-release; then
59 $maysudo "$dnf" config-manager --set-enabled crb
60 fi
61
62 $maysudo "$dnf" install -y "${deps[@]}"
63 exit 0
64fi
65
66# openSUSE
67# https://software.opensuse.org/
68zyp=$(command -v zypper || true)
69if [[ -n $zyp ]]; then
70 deps=(
71 alsa-devel
72 fontconfig-devel
73 wayland-devel
74 libxkbcommon-x11-devel
75 openssl-devel
76 libzstd-devel
77 libvulkan1
78 )
79 $maysudo "$zyp" install -y "${deps[@]}"
80 exit 0
81fi
82
83# Arch, Manjaro, etc.
84# https://archlinux.org/packages
85pacman=$(command -v pacman || true)
86if [[ -n $pacman ]]; then
87 deps=(
88 alsa-lib
89 fontconfig
90 wayland
91 libgit2
92 libxkbcommon-x11
93 openssl
94 zstd
95 pkgconf
96 )
97 $maysudo "$pacman" -S --needed --noconfirm "${deps[@]}"
98 exit 0
99fi
100
101# Void
102# https://voidlinux.org/packages/
103xbps=$(command -v xbps-install || true)
104if [[ -n $xbps ]]; then
105 deps=(
106 alsa-lib-devel
107 fontconfig-devel
108 libxcb-devel
109 libxkbcommon-devel
110 libzstd-devel
111 openssl-devel
112 wayland-devel
113 vulkan-loader
114 )
115 $maysudo "$xbps" -Syu "${deps[@]}"
116 exit 0
117fi
118
119# Gentoo
120# https://packages.gentoo.org/
121emerge=$(command -v emerge || true)
122if [[ -n $emerge ]]; then
123 deps=(
124 app-arch/zstd
125 dev-libs/openssl
126 dev-libs/wayland
127 media-libs/alsa-lib
128 media-libs/fontconfig
129 media-libs/vulkan-loader
130 x11-libs/libxcb
131 x11-libs/libxkbcommon
132 )
133 $maysudo "$emerge" -u "${deps[@]}"
134 exit 0
135fi
136
137echo "Unsupported Linux distribution in script/linux"