linux

  1#!/usr/bin/env bash
  2
  3set -xeuo pipefail
  4
  5# if root or if sudo/unavailable, define an empty variable
  6if [ "$(id -u)" -eq 0 ]
  7then maysudo=''
  8else maysudo="$(command -v sudo || command -v doas || true)"
  9fi
 10
 11function finalize {
 12  # after packages install (curl, etc), get the rust toolchain
 13  which rustup > /dev/null 2>&1 || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
 14  # cat <<EOF
 15
 16  source script/install-wild
 17# Note: It's recommended to install Wild for faster builds.
 18#       Run script/install-wild.
 19
 20# Finished installing Linux dependencies with script/linux
 21# EOF
 22}
 23
 24# Ubuntu, Debian, Mint, Kali, Pop!_OS, Raspbian, etc.
 25apt=$(command -v apt-get || true)
 26if [[ -n $apt ]]; then
 27  deps=(
 28    gcc
 29    g++
 30    libasound2-dev
 31    libfontconfig-dev
 32    libwayland-dev
 33    libx11-xcb-dev
 34    libxkbcommon-x11-dev
 35    libssl-dev
 36    libzstd-dev
 37    libvulkan1
 38    libgit2-dev
 39    make
 40    cmake
 41    clang
 42    jq
 43    git
 44    curl
 45    gettext-base
 46    elfutils
 47    libsqlite3-dev
 48    musl-tools
 49    musl-dev
 50    build-essential
 51  )
 52  if (grep -qP 'PRETTY_NAME="(Debian|Raspbian).+13' /etc/os-release); then
 53      # libstdc++-14-dev is in build-essential
 54      deps+=( mold )
 55  elif (grep -qP 'PRETTY_NAME="(Linux Mint 22|.+24\.(04|10))' /etc/os-release); then
 56    deps+=( mold libstdc++-14-dev )
 57  elif (grep -qP 'PRETTY_NAME="((Debian|Raspbian).+12|Linux Mint 21|.+22\.04)' /etc/os-release); then
 58    deps+=( mold libstdc++-12-dev )
 59  elif (grep -qP 'PRETTY_NAME="((Debian|Raspbian).+11|Linux Mint 20|.+20\.04)' /etc/os-release); then
 60    deps+=( libstdc++-10-dev )
 61  fi
 62
 63  $maysudo "$apt" update
 64  $maysudo "$apt" install -y "${deps[@]}"
 65  finalize
 66  exit 0
 67fi
 68
 69# Fedora, CentOS, RHEL, Alma, Amazon 2023, Oracle, etc.
 70dnf=$(command -v dnf || true)
 71# Old Redhat (yum only): Amazon Linux 2, Oracle Linux 7, etc.
 72yum=$(command -v yum || true)
 73
 74if [[ -n $dnf ]] || [[ -n $yum ]]; then
 75  pkg_cmd="${dnf:-${yum}}"
 76  deps=(
 77    musl-gcc
 78    gcc
 79    clang
 80    cmake
 81    alsa-lib-devel
 82    fontconfig-devel
 83    wayland-devel
 84    libxcb-devel
 85    libxkbcommon-x11-devel
 86    openssl-devel
 87    libzstd-devel
 88    vulkan-loader
 89    sqlite-devel
 90    jq
 91    git
 92    tar
 93  )
 94  # perl used for building openssl-sys crate. See: https://docs.rs/openssl/latest/openssl/
 95  if grep -qP '^ID="?(fedora)' /etc/os-release; then
 96    deps+=(
 97      perl-FindBin
 98      perl-IPC-Cmd
 99      perl-File-Compare
100      perl-File-Copy
101      mold
102    )
103  elif grep -qP '^ID="?(rhel|rocky|alma|centos|ol)' /etc/os-release; then
104    deps+=( perl-interpreter )
105  fi
106
107  # gcc-c++ is g++ on RHEL8 and 8.x clones
108  if grep -qP '^ID="?(rhel|rocky|alma|centos|ol)' /etc/os-release \
109      && grep -qP '^VERSION_ID="?(8)' /etc/os-release; then
110    deps+=( gcc-c++ )
111  else
112    deps+=( g++ )
113  fi
114
115  # libxkbcommon-x11-devel is in a non-default repo on RHEL 8.x/9.x (except on AmazonLinux)
116  if grep -qP '^VERSION_ID="?(8|9)' /etc/os-release && grep -qP '^ID="?(rhel|rocky|centos|alma|ol)' /etc/os-release; then
117    $maysudo dnf install -y 'dnf-command(config-manager)'
118    if grep -qP '^PRETTY_NAME="(AlmaLinux 8|Rocky Linux 8)' /etc/os-release; then
119      $maysudo dnf config-manager --set-enabled powertools
120    elif grep -qP '^PRETTY_NAME="((AlmaLinux|Rocky|CentOS Stream) 9|Red Hat.+(8|9))' /etc/os-release; then
121      $maysudo dnf config-manager --set-enabled crb
122    elif grep -qP '^PRETTY_NAME="Oracle Linux Server 8' /etc/os-release; then
123      $maysudo dnf config-manager --set-enabled ol8_codeready_builder
124    elif grep -qP '^PRETTY_NAME="Oracle Linux Server 9' /etc/os-release; then
125      $maysudo dnf config-manager --set-enabled ol9_codeready_builder
126    else
127      echo "Unexpected distro" && grep 'PRETTY_NAME' /etc/os-release && exit 1
128    fi
129  fi
130
131  $maysudo "$pkg_cmd" install -y "${deps[@]}"
132  finalize
133  exit 0
134fi
135
136# openSUSE
137# https://software.opensuse.org/
138zyp=$(command -v zypper || true)
139if [[ -n $zyp ]]; then
140  deps=(
141    alsa-devel
142    clang
143    cmake
144    fontconfig-devel
145    gcc
146    gcc-c++
147    git
148    gzip
149    jq
150    libvulkan1
151    libx11-devel
152    libxcb-devel
153    libxkbcommon-devel
154    libxkbcommon-x11-devel
155    libzstd-devel
156    make
157    mold
158    openssl-devel
159    sqlite3-devel
160    tar
161    wayland-devel
162    xcb-util-devel
163  )
164  $maysudo "$zyp" install -y "${deps[@]}"
165  finalize
166  exit 0
167fi
168
169# Arch, Manjaro, etc.
170# https://archlinux.org/packages
171pacman=$(command -v pacman || true)
172if [[ -n $pacman ]]; then
173  deps=(
174    gcc
175    clang
176    musl
177    cmake
178    alsa-lib
179    fontconfig
180    wayland
181    libgit2
182    libxcb
183    libxkbcommon-x11
184    openssl
185    zstd
186    pkgconf
187    mold
188    sqlite
189    jq
190    git
191  )
192  $maysudo "$pacman" -Syu --needed --noconfirm "${deps[@]}"
193  finalize
194  exit 0
195fi
196
197# Void
198# https://voidlinux.org/packages/
199xbps=$(command -v xbps-install || true)
200if [[ -n $xbps ]]; then
201  deps=(
202    gettext-devel
203    clang
204    cmake
205    jq
206    elfutils-devel
207    gcc
208    alsa-lib-devel
209    fontconfig-devel
210    libxcb-devel
211    libxkbcommon-devel
212    libzstd-devel
213    openssl-devel
214    wayland-devel
215    vulkan-loader
216    mold
217    sqlite-devel
218  )
219  $maysudo "$xbps" -Syu "${deps[@]}"
220  finalize
221  exit 0
222fi
223
224# Gentoo
225# https://packages.gentoo.org/
226emerge=$(command -v emerge || true)
227if [[ -n $emerge ]]; then
228  deps=(
229    app-arch/zstd
230    app-misc/jq
231    dev-libs/openssl
232    dev-libs/wayland
233    dev-util/cmake
234    media-libs/alsa-lib
235    media-libs/fontconfig
236    media-libs/vulkan-loader
237    x11-libs/libxcb
238    x11-libs/libxkbcommon
239    sys-devel/mold
240    dev-db/sqlite
241  )
242  $maysudo "$emerge" -u "${deps[@]}"
243  finalize
244  exit 0
245fi
246
247echo "Unsupported Linux distribution in script/linux"
248exit 1