Tim Crawford 968a612824 scripts: Address shellcheck issues
Report issues by shell files with:

    git ls-files '*.sh' | xargs shellcheck --exclude=SC2162

Address the following:

- SC1087: Use braces when expanding arrays
- SC1091: Not following
- SC2004: `$`/`${}` is unnecessary on arithmetic variables
- SC2024: `sudo` doesn't affect redirects
- SC2034: foo appears unused. Verify it or export it
- SC2086: Double quote to prevent globbing and word splitting
- SC2087: Quote `EOF`
- SC2115: Use `"${var:?}"` to ensure this never expands to `/*`
- SC2148: Add a shebang

Addresses (at least partially) some POSIX/dash issues:

- SC2113: `function` keyword is non-standard
- SC3010: In POSIX sh, `[[` `]]` is undefined
- SC3014: In POSIX sh, `==` in place of `=` is undefined
- SC3020: In POSIX sh, `&>` is undefined
- SC3046: In POSIX sh, `source` in place of `.` is undefined

Does not address:

- SC2162: `read` without `-r` will mangle backslashes
- Any other POSIX/dash-specific issues

Signed-off-by: Tim Crawford <tcrawford@system76.com>
2023-10-19 14:45:22 -06:00

107 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
# shellcheck disable=SC1091
set -eE
msg() {
echo -e "\x1B[1m$*\x1B[0m" >&2
}
trap 'msg "\x1B[31mFailed to install dependencies!"' ERR
. /etc/os-release
msg "Installing system build dependencies"
if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then
sudo apt-get --quiet update
sudo apt-get --quiet install \
--no-install-recommends \
--assume-yes \
build-essential \
ccache \
cmake \
curl \
devmem2 \
dosfstools \
flashrom \
git-lfs \
libncurses-dev \
libudev-dev \
msr-tools \
mtools \
parted \
python-is-python3 \
python3-distutils \
uuid-dev \
zlib1g-dev
elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then
sudo dnf group install c-development
sudo dnf install \
--assumeyes \
ccache \
cmake \
curl \
dosfstools \
flashrom \
git-lfs \
libuuid-devel \
msr-tools \
mtools \
ncurses-devel \
parted \
patch \
python-unversioned-command \
python3 \
systemd-devel \
zlib-devel
elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
sudo pacman -S \
--noconfirm \
ccache \
cmake \
curl \
dosfstools \
flashrom \
git-lfs \
msr-tools \
mtools \
ncurses \
parted \
patch \
python \
python-distutils-extra \
systemd-libs
else
msg "Unknown system ID: ${ID}"
msg "Please add support for your distribution to: $0"
exit 1
fi
# Don't run on Jenkins
if [ -z "${CI}" ]; then
msg "Installing GIT LFS hooks"
git lfs install
msg "Downloading GIT LFS artifacts"
git lfs pull
fi
msg "Initializing submodules"
git submodule update --init --recursive --checkout --progress
msg "Building coreboot toolchains"
./scripts/coreboot-sdk.sh
msg "Installing Rust toolchain and components"
./scripts/install-rust.sh
msg "Installing EC dependencies"
pushd ec
./scripts/deps.sh
popd
msg "\x1B[32mSuccessfully installed dependencies"
echo "Ready to run ./scripts/build.sh [model]" >&2