Files
IronFox/scripts/bootstrap.sh
Akash Yadav aeb8d3a5f0 feat: lint shell scripts with shellcheck + shfmt in CI and pre-commit
ironfox-oss/IronFox!162
Add a blocking `lint` CI stage (runs first, on a lightweight Alpine
image) plus a core.hooksPath pre-commit hook, with scripts/lint.sh as
the shared runner for CI, the hook, and manual use. Checks are
configured in .shellcheckrc and formatting in .editorconfig.

Reformat all scripts with shfmt (2-space indent, switch-case indent,
space redirects) via .editorconfig, so a bare `shfmt` is consistent
everywhere. bootstrap.sh installs shellcheck + shfmt per-OS and
enables the pre-commit hook.

The hook is a convenience (bypassable with --no-verify); the CI
`lint-scripts` job is the enforcement gate. SC2086/SC2046 are
disabled for now as tracked follow-up.

MR-author: Akash Yadav <itsaky01@gmail.com>
Co-authored-by: Akash Yadav <contact@itsaky.com>
Approved-by: celenity <celenity@celenity.dev>
Merged-by: celenity <celenity@celenity.dev>
2026-07-31 02:33:10 +00:00

199 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
# Script to assist with creation of an IronFox build environment
set -euo pipefail
# Set-up our environment
if [[ -z "${IRONFOX_SET_ENVS+x}" ]]; then
/bin/bash $(dirname $0)/env.sh
fi
source $(dirname $0)/env.sh
# Include utilities
source "${IRONFOX_UTILS}"
# Get our platform, OS, and architecture
source "${IRONFOX_ENV_HELPERS}"
# Set verbosity
if [[ "${IRONFOX_VERBOSE}" == 1 ]]; then
set -x
else
set +x
fi
function error_fn() {
echo
echo -e "\033[31mSomething went wrong! The script failed.\033[0m"
echo -e "\033[31mPlease report this (with the output message) to https://gitlab.com/ironfox-oss/IronFox/-/issues\033[0m"
echo
exit 1
}
# Install dependencies
echo_green_text "Installing dependencies..."
echo_green_text "Detected operating system: ${IRONFOX_OS}"
# macOS, secureblue
## (Both use Homebrew)
if [[ "${IRONFOX_OS}" == 'osx' ]] || [[ "${IRONFOX_OS}" == 'secureblue' ]]; then
# Ensure Homebrew is installed
if [[ -z "${HOMEBREW_PREFIX+x}" ]]; then
echo_red_text "Homebrew is not installed! Aborting..."
echo_red_text "Please install Homebrew and try again..."
echo_green_text "https://brew.sh/"
exit 1
fi
export HOMEBREW_NO_ASK=1
# Ensure we're up to date
brew update --force || error_fn
echo
brew upgrade --greedy || error_fn
echo
if [[ "${IRONFOX_OS}" == 'osx' ]]; then
# Ensure Xcode command line tools are installed
if ! /usr/bin/xcode-select -p &> /dev/null; then
/usr/bin/xcode-select --install || error_fn
echo
fi
# Install OS X dependencies
brew install \
curl \
coreutils \
gawk \
git \
gmake \
gnu-sed \
gnu-tar \
gpatch \
m4 \
make \
xz \
zlib || error_fn
echo
fi
# Install our dependencies...
brew install \
cmake \
jq \
nasm \
ninja \
perl \
shasum \
shellcheck \
shfmt \
yq || error_fn
echo
# For secureblue, we also need clang and zlib-devel
if [[ "${IRONFOX_OS}" == 'secureblue' ]]; then
# Ensure we're up to date
/usr/bin/rpm-ostree refresh-md --force || error_fn
echo
/usr/bin/ujust update-system || error_fn
echo
# Install clang and zlib-devel
/usr/bin/rpm-ostree install \
clang \
zlib-devel || error_fn
echo
# We now unfortunately have to restart the system :/
echo_red_text "To apply the clang and zlib installations, your system will now reboot."
"${IRONFOX_SLEEP}" 5 || error_fn
echo
echo_green_text "Press enter to continue."
read -r
/usr/bin/systemctl reboot || error_fn
echo
fi
# Fedora
elif [[ "${IRONFOX_OS}" == 'fedora' ]]; then
# Ensure we're up to date
sudo dnf update -y --refresh || error_fn
echo
# Install our dependencies...
sudo dnf install -y \
cmake \
clang \
gawk \
git \
jq \
m4 \
make \
nasm \
ninja-build \
patch \
perl \
shasum \
ShellCheck \
shfmt \
xz \
yq \
zlib-devel || error_fn
echo
# Ubuntu
elif [[ "${IRONFOX_OS}" == 'ubuntu' ]]; then
# Ensure we're up to date
sudo apt update || error_fn
echo
sudo apt upgrade || error_fn
echo
sudo apt install -y \
apt-transport-https \
cmake \
clang-18 \
curl \
git \
gpg \
make \
nasm \
ninja-build \
patch \
perl \
shellcheck \
tar \
unzip \
xz-utils \
yq \
zlib1g-dev || error_fn
echo
# shfmt isn't reliably packaged on all Ubuntu releases; fetch the static
# binary if apt didn't provide it.
if ! command -v shfmt > /dev/null 2>&1; then
echo_green_text "Installing shfmt..."
readonly SHFMT_VERSION='v3.13.1'
SHFMT_ARCH="$(dpkg --print-architecture)"
readonly SHFMT_ARCH
sudo curl -fsSL -o /usr/local/bin/shfmt \
"https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/shfmt_${SHFMT_VERSION}_linux_${SHFMT_ARCH}" || error_fn
sudo chmod +x /usr/local/bin/shfmt || error_fn
echo
fi
else
echo_red_text "Apologies, your operating system is currently not supported."
echo_red_text "If you think this is a mistake, please let us know!"
echo_green_text "https://gitlab.com/ironfox-oss/IronFox/-/issues"
echo_red_text "Otherwise, please try again on a system running the latest version of Fedora, macOS, secureblue, or Ubuntu."
exit 1
fi
# Enable the pre-commit hook so shell scripts are linted (shellcheck + shfmt)
# before each commit. CI enforces the same checks, so this is just a fast local
# safeguard (and is bypassable with `git commit --no-verify`).
echo_green_text "Configuring git pre-commit hook..."
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
git -C "${REPO_ROOT}" config core.hooksPath scripts/git-hooks || error_fn
echo