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 ]; then
 7    maysudo=''
 8else
 9    maysudo="$(command -v sudo || command -v doas || true)"
10fi
11
12function finalize {
13    # after packages install (curl, etc), get the rust toolchain
14    which rustup >/dev/null 2>&1 || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
15    echo "Finished installing FreeBSD dependencies with script/freebsd"
16}
17
18# FreeBSD
19# https://www.freebsd.org/ports/
20pkg=$(command -v pkg || true)
21if [[ -n $pkg ]]; then
22    deps=(
23        cmake
24        gcc
25        git
26        llvm
27        protobuf
28        rustup-init
29        libx11
30        alsa-lib
31    )
32    $maysudo "$pkg" install "${deps[@]}"
33    finalize
34    exit 0
35fi