chore: update buildscript and documentation

Signed-off-by: desertwitch <24509509+desertwitch@users.noreply.github.com>
This commit is contained in:
desertwitch
2025-11-19 10:25:37 +01:00
parent 66e7c16de3
commit 2e90372692
3 changed files with 378 additions and 126 deletions

View File

@@ -1,16 +1,16 @@
This file is embedded into the GRUB bootloaders at build-time
Helps GRUB find our ShredOS volume when it cannot (Ventoy BIOS)
This file is embedded into the GRUB bootloaders at build-time.
Helps GRUB find our ShredOS volume when it cannot (Ventoy BIOS).
There is no point to put it anywhere on the USB - so don't do that.
Keep consistent with BR2_TARGET_ROOTFS_ISO9660_GRUB2_EFI_IDENT_FILE
when building any configurations that build both an ISO and the IMG.
Do not use the version file as identification file though, because
the ISO9660 filesystem does not have it (but has the needed grub.cfg),
read-only ISO9660 filesystem doesn't have it (but has needed grub.cfg),
so you should always use a unique file not otherwise used for anything.
Also ensure it is in a location where users cannot delete it by accident.
Note that contrary to the GNU manual the BIOS bootloader seems to need an
Note that contrary to the GNU manual the BIOS bootloader seems to need the
explicit "configfile" directive, otherwise the Buildroot static prefix takes
precedence over the actual found volume path (which may be entirely different).

View File

@@ -1,68 +1,131 @@
#!/bin/bash
set -euo pipefail
################################################################################
# Usage:
# FAIL_ON_ERROR=0|1 QUICK_BUILD=0|1 NEW_VERSION="STRING" ./build_all.sh
# Usage: ./build_all_shredos.sh [x64|x32|all]
#
# Examples:
# ./build_all.sh
# FAIL_ON_ERROR=0 QUICK_BUILD=0 ./build_all.sh
# NEW_VERSION="2024.11_27_x86-64_0.38" ./build_all.sh
# Arguments:
# x64 - Build only x86-64 configurations
# x32 - Build only i586 (32-bit) configurations
# all - Build all configurations (64-bit first, then 32-bit)
#
# Environment Variables:
# FAIL_ON_ERROR - 0=continue on failure, 1=exit on first failure (default: 1)
# QUICK_BUILD - 0=full clean between configs, 1=grub2-rebuild only (default: 1)
# NEW_VERSION - Version string (default: prompts user & keeps current on ENTER)
# DRY_RUN=0|1 - Output all commands that would be executed (default: 0)
# PRE_CLEAN=0|1 - Do an initial 'make clean' before starting (default: 1)
# QUICK_BUILD=0|1 - Do not full rebuild for same architecture (default: 0)
# FAST_FAIL=0|1 - Exit on first configuration build failure (default: 1)
# NEW_VERSION=STR - Set version string (default: prompts user)
#
# Examples:
# ./build_all_shredos.sh x64
# ./build_all_shredos.sh all
# QUICK_BUILD=1 ./build_all_shredos.sh x32
# NEW_VERSION="2024.11_27_x86-64_0.38" ./build_all_shredos.sh x64
################################################################################
################################################################################
# 0 = continue to the next configuration if one fails to build
# 1 = exit the entire script if one configuration fails to build
FAIL_ON_ERROR="${FAIL_ON_ERROR:-1}"
################################################################################
################################################################################
# 0 = "make clean" between same architecture configs (much slower)
# 1 = "make grub2-rebuild" between same architecture configs (much faster)
QUICK_BUILD="${QUICK_BUILD:-1}"
################################################################################
################################################################################
# Location of the version file:
VERSION_FILE="board/shredos/fsoverlay/etc/shredos/version.txt"
x64_configs=(
# 64-bit configurations to build:
X64_CONFIGS=(
"shredos_defconfig"
"shredos_img_defconfig"
"shredos_iso_defconfig"
"shredos_iso_aio_defconfig"
)
x32_configs=(
# 32-bit configurations to build:
X32_CONFIGS=(
"shredos_i586_defconfig"
"shredos_img_i586_defconfig"
"shredos_iso_i586_defconfig"
"shredos_iso_aio_i586_defconfig"
)
# Packages always needing rebuild between runs, even for the same architecture.
# This only applies when QUICK_BUILD is enabled, otherwise rebuilds everything.
ALWAYS_REBUILD_PKGS=(
"grub2"
)
################################################################################
set -e
trap 'exit 1' SIGINT
trap 'exit 1' SIGTERM
DRY_RUN="${DRY_RUN:-0}"
PRE_CLEAN="${PRE_CLEAN:-1}"
QUICK_BUILD="${QUICK_BUILD:-0}"
FAST_FAIL="${FAST_FAIL:-1}"
NEW_VERSION="${NEW_VERSION:-}"
x64_success=0
x64_failed=0
x32_success=0
x32_failed=0
X64_SUCCESS=0
X64_FAILED=0
X32_SUCCESS=0
X32_FAILED=0
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
RED="\033[0;31m"
RESET="\033[0m"
FORCE_CLEAN=0
print_usage() {
echo
echo "Usage: $0 [x64|x32|all]"
echo ""
echo "Arguments:"
echo " x64 - Build only x86-64 configurations"
echo " x32 - Build only i586 (32-bit) configurations"
echo " all - Build all configurations (64-bit first, then 32-bit)"
echo ""
echo "Environment Variables:"
echo " DRY_RUN=0|1 - Output all commands that would be executed (default: 0)"
echo " PRE_CLEAN=0|1 - Do an initial 'make clean' before starting (default: 1)"
echo " QUICK_BUILD=0|1 - Do not full rebuild for same architecture (default: 0)"
echo " FAST_FAIL=0|1 - Exit on first failure (default: 1)"
echo " NEW_VERSION=STR - Set version string (default: prompts user)"
echo ""
echo "Examples:"
echo " $0 x64"
echo " $0 all"
echo " QUICK_BUILD=1 PRE_CLEAN=0 $0 x32"
echo
}
parse_arguments() {
if [ $# -eq 0 ]; then
printf "%b" "$RED"
echo "Error: Missing architecture argument"
printf "%b" "$RESET"
print_usage
exit 1
fi
BUILD_TARGET="$1"
case "$BUILD_TARGET" in
x64)
X32_CONFIGS=()
;;
x32)
X64_CONFIGS=()
;;
all)
;;
*)
printf "%b" "$RED"
echo "Error: Invalid architecture '$BUILD_TARGET'"
echo "Must be one of: x64, x32, all"
printf "%b" "$RESET"
print_usage
exit 1
;;
esac
}
prompt_version() {
local CURRENT_VERSION=""
local current_version=""
if [ -f "$VERSION_FILE" ]; then
CURRENT_VERSION=$(cat "$VERSION_FILE")
current_version=$(cat "$VERSION_FILE")
else
printf "%b" "$RED"
echo
@@ -77,8 +140,8 @@ prompt_version() {
if [ -z "$NEW_VERSION" ]; then
echo
echo "x86-64 and i586 will be replaced/switched around during builds (depending on architecture)"
read -rp "Enter new version or press ENTER to keep existing [${CURRENT_VERSION}]: " NEW_VERSION
[ -z "$NEW_VERSION" ] && NEW_VERSION="$CURRENT_VERSION"
read -rp "Enter new version or press ENTER to keep existing [${current_version}]: " NEW_VERSION
[ -z "$NEW_VERSION" ] && NEW_VERSION="$current_version"
fi
echo "$NEW_VERSION" > "$VERSION_FILE"
@@ -93,37 +156,48 @@ prompt_version() {
}
display_build_plan() {
local total_configs=$((${#x64_configs[@]} + ${#x32_configs[@]}))
local total_configs=$((${#X64_CONFIGS[@]} + ${#X32_CONFIGS[@]}))
printf "%b" "$GREEN"
echo
echo "==============================================="
echo "PLANNING TO BUILD:"
echo "==============================================="
echo "Version: $NEW_VERSION"
echo "Fail on Error: $FAIL_ON_ERROR"
echo "Quick Build: $QUICK_BUILD"
echo "Total Configs: $total_configs"
echo "Version: $NEW_VERSION"
echo "Dry-Run: $DRY_RUN"
echo "Pre-Clean: $PRE_CLEAN"
echo "Quick Build: $QUICK_BUILD"
echo "Fast Failure: $FAST_FAIL"
echo "Total Configurations: $total_configs"
echo "Building Architectures: $BUILD_TARGET"
echo "==============================================="
echo
printf "%b" "$RESET"
if [ ${#x64_configs[@]} -gt 0 ]; then
echo "64-bit targets (${#x64_configs[@]}):"
for config in "${x64_configs[@]}"; do
if [ ${#X64_CONFIGS[@]} -gt 0 ]; then
echo "64-bit configurations (${#X64_CONFIGS[@]}):"
for config in "${X64_CONFIGS[@]}"; do
echo " - $config"
done
echo
fi
if [ ${#x32_configs[@]} -gt 0 ]; then
echo "32-bit targets (${#x32_configs[@]}):"
for config in "${x32_configs[@]}"; do
if [ ${#X32_CONFIGS[@]} -gt 0 ]; then
echo "32-bit configurations (${#X32_CONFIGS[@]}):"
for config in "${X32_CONFIGS[@]}"; do
echo " - $config"
done
echo
fi
if [ ${#ALWAYS_REBUILD_PKGS[@]} -gt 0 ]; then
echo "Packages that will be re-built between same-architecture runs (${#ALWAYS_REBUILD_PKGS[@]}):"
for package in "${ALWAYS_REBUILD_PKGS[@]}"; do
echo " - $package"
done
echo
fi
printf "%b" "$GREEN"
echo "==============================================="
echo "Configurations to build can be amended inside the script."
@@ -135,94 +209,277 @@ display_build_plan() {
replace_version() {
local from=$1
local to=$2
if [ -f "$VERSION_FILE" ]; then
sed -i "s/$from/$to/g" "$VERSION_FILE"
sed -i "s@$from@$to@g" "$VERSION_FILE"
fi
}
run_cmd() {
if [ "$DRY_RUN" -eq 1 ]; then
echo "[DRY_RUN] $*"
else
"$@"
fi
}
build_config() {
local config=$1
local arch=$2
local index="$1"
local config="$2"
local arch="$3"
local log_file="dist/${config}.log"
printf "%b" "$YELLOW"
echo
echo "============================================"
echo "Building $config ($arch)"
echo "Started: '$config' ($arch)"
echo "============================================"
echo
printf "%b" "$RESET"
if [ "$QUICK_BUILD" -eq 1 ]; then
make "$config"
make grub2-rebuild
# Build | QuickBuild=1, PreClean=1 | QuickBuild=0, PreClean=1 | QuickBuild=1, PreClean=0 | QuickBuild=0, PreClean=0
# -------|---------------------------|---------------------------|---------------------------|---------------------------
# x64 #0 | config -> make | config -> make | config -> rebuild -> make | config -> rebuild -> make
# x64 #1 | config -> rebuild -> make | clean -> config -> make | config -> rebuild -> make | clean -> config -> make
# x64 #2+| config -> rebuild -> make | clean -> config -> make | config -> rebuild -> make | clean -> config -> make
# x32 #0 | clean -> config -> make | clean -> config -> make | clean -> config -> make | clean -> config -> make
# x32 #1+| config -> rebuild -> make | clean -> config -> make | config -> rebuild -> make | clean -> config -> make
if [ "$index" -ne 0 ] && [ "$QUICK_BUILD" -eq 1 ] && [ "$FORCE_CLEAN" -ne 1 ]; then
# If it's not the first configuration, and quick-build is enabled,
# and a clean is not otherwise forced, just rebuild necessary packages.
echo
echo "============================================"
echo "Loading configuration '$config' ($arch)..."
echo "============================================"
echo
if ! run_cmd make "$config"; then
build_config_failed "$config" "$arch" "$log_file"
return 1
fi
echo
echo "============================================"
echo "Rebuilding packages for '$config' ($arch)..."
echo "============================================"
echo
for pkg in "${ALWAYS_REBUILD_PKGS[@]}"; do
if ! run_cmd make "${pkg}-rebuild"; then
build_config_failed "$config" "$arch" "$log_file"
return 1
fi
done
else
make clean
make "$config"
if [ "$index" -ne 0 ] || [ "$FORCE_CLEAN" -eq 1 ]; then
# If it's not the first configuration, or the clean was forced
# (due to architecture change), clean the building environment.
echo
echo "============================================"
echo "Running 'make clean' for '$config' ($arch)..."
echo "============================================"
echo
if ! run_cmd make clean; then
build_config_failed "$config" "$arch" "$log_file"
return 1
fi
fi
echo
echo "============================================"
echo "Loading configuration '$config' ($arch)..."
echo "============================================"
echo
if ! run_cmd make "$config"; then
build_config_failed "$config" "$arch" "$log_file"
return 1
fi
if [ "$index" -eq 0 ] && [ "$PRE_CLEAN" -eq 0 ] && [ "$FORCE_CLEAN" -ne 1 ]; then
# If it's the first configuration in a deliberately unclean environment,
# and clean was not otherwise forced, at least rebuild the necessary packages.
echo
echo "============================================"
echo "Rebuilding packages for '$config' ($arch)..."
echo "============================================"
echo
for pkg in "${ALWAYS_REBUILD_PKGS[@]}"; do
if ! run_cmd make "${pkg}-rebuild"; then
build_config_failed "$config" "$arch" "$log_file"
return 1
fi
done
fi
fi
[ ! "$FAIL_ON_ERROR" -eq 1 ] && set +e
make 2>&1 | tee "$log_file"
local make_status=${PIPESTATUS[0]}
[ ! "$FAIL_ON_ERROR" -eq 1 ] && set -e
FORCE_CLEAN=0 # Reset previous dirty state
if [ "$make_status" -eq 0 ]; then
mv "$log_file" "dist/${config}-SUCCESS.log"
mkdir -p "dist/$config"
mv output/images/shredos*.iso "dist/$config/" 2>/dev/null || true
mv output/images/shredos*.img "dist/$config/" 2>/dev/null || true
printf "%b" "$GREEN"
echo
echo "============================================"
echo "Building '$config' ($arch)..."
echo "============================================"
echo
if run_cmd make 2>&1 | tee "$log_file"; then
echo
echo "==============================================="
echo "$config build ($arch) success"
echo "==============================================="
echo "============================================"
echo "Finishing '$config' ($arch)..."
echo "============================================"
echo
printf "%b\n" "$RESET"
if [ "$arch" = "x64" ]; then
((x64_success++))
else
((x32_success++))
fi
build_config_success "$config" "$arch" "$log_file"
return 0
else
mv "$log_file" "dist/${config}-FAILED.log"
echo
echo "============================================"
echo "Finishing '$config' ($arch)..."
echo "============================================"
echo
build_config_failed "$config" "$arch" "$log_file"
return 1
fi
}
print_summary() {
local total_success=$((X64_SUCCESS + X32_SUCCESS))
local total_failed=$((X64_FAILED + X32_FAILED))
local total_builds=$((total_success + total_failed))
echo
echo "============================================"
echo "BUILD SUMMARY"
echo "============================================"
echo "64-bit builds: $X64_SUCCESS succeeded, $X64_FAILED failed"
echo "32-bit builds: $X32_SUCCESS succeeded, $X32_FAILED failed"
echo "--------------------------------------------"
echo "Total: $total_success succeeded, $total_failed failed (out of $total_builds)"
echo "--------------------------------------------"
echo "You will find all output files of the builds in the 'dist/' folder."
echo "============================================"
echo
}
build_config_success() {
local config="$1"
local arch="$2"
local log_file="$3"
if [ -f "$log_file" ]; then
run_cmd mv "$log_file" "dist/${config}-SUCCESS.log"
fi
run_cmd mkdir -p "dist/$config"
run_cmd mv output/images/shredos*.iso "dist/$config/" 2>/dev/null || true
run_cmd mv output/images/shredos*.img "dist/$config/" 2>/dev/null || true
printf "%b" "$GREEN"
echo
echo "==============================================="
echo "SUCCESS: '$config' ($arch)"
echo "==============================================="
echo
printf "%b" "$RESET"
if [ "$arch" = "x64" ]; then
((X64_SUCCESS++))
else
((X32_SUCCESS++))
fi
}
build_config_failed() {
local config="$1"
local arch="$2"
local log_file="$3"
if [ -f "$log_file" ]; then
run_cmd mv "$log_file" "dist/${config}-FAILED.log"
fi
printf "%b" "$RED"
echo
echo "==============================================="
echo "FAILURE: '$config' ($arch)"
echo "==============================================="
echo
printf "%b" "$RESET"
if [ "$arch" = "x64" ]; then
((X64_FAILED++))
else
((X32_FAILED++))
fi
if [ "$FAST_FAIL" -eq 1 ]; then
printf "%b" "$RED"
echo
echo "==============================================="
echo "$config build ($arch) failed"
echo "Fast Failure Mode is enabled - not proceeding..."
echo "==============================================="
echo
printf "%b\n" "$RESET"
if [ "$arch" = "x64" ]; then
((x64_failed++))
else
((x32_failed++))
fi
return 1
printf "%b" "$RESET"
exit 1
fi
}
################################################################################
parse_arguments "$@"
prompt_version
display_build_plan
echo "Starting these builds in 10 seconds... (press CTRL+C to cancel)"
if [ "$DRY_RUN" -eq 1 ]; then
printf "%b" "$YELLOW"
echo
echo "==============================================="
echo "DRY RUN - NO ACTUAL CHANGES WILL BE MADE"
echo "DISREGARD WARNINGS ABOUT 'MAKE CLEAN' ETC..."
echo "==============================================="
echo
printf "%b" "$RESET"
fi
if [ "$PRE_CLEAN" -eq 1 ]; then
printf "%b" "$RED"
echo
echo "==============================================="
echo "Beware - WILL run a MAKE CLEAN before starting building!"
echo "Press ENTER in the next 10 seconds to skip this step..."
echo "or otherwise (if you want to MAKE CLEAN) - just wait..."
echo "==============================================="
echo
printf "%b" "$RESET"
if read -rt 10; then
PRE_CLEAN=0
echo "Skipped cleaning the building stage (no 'make clean')..."
fi
fi
printf "%b" "$YELLOW"
echo
echo "==============================================="
echo "Starting build in 10 seconds... (press CTRL+C to cancel)"
if [ "$PRE_CLEAN" -eq 1 ]; then
printf "%b" "$RESET"
printf "%b" "$RED"
echo "Beware - WILL run a MAKE CLEAN before starting building!"
printf "%b" "$RESET"
printf "%b" "$YELLOW"
fi
echo "==============================================="
echo
printf "%b" "$RESET"
sleep 10
echo "Running 'make clean' on the building environment..."
make clean
if [ "$PRE_CLEAN" -eq 1 ]; then
echo "Running 'make clean' on the building environment..."
run_cmd make clean
fi
echo "Removing and recreating 'dist/' folder (if it exists)..."
rm -r dist || true
mkdir -p dist
run_cmd rm -r dist || true
run_cmd mkdir -p dist
echo "Starting to build..."
trap 'print_summary' EXIT
if [ ${#x64_configs[@]} -gt 0 ]; then
if [ ${#X64_CONFIGS[@]} -gt 0 ]; then
echo
echo "==============================================="
echo "Starting 64-bit builds..."
@@ -230,14 +487,19 @@ if [ ${#x64_configs[@]} -gt 0 ]; then
echo
replace_version "i586" "x86-64"
for config in "${x64_configs[@]}"; do
build_config "$config" "x64" || true
CFG_INDEX=0
for config in "${X64_CONFIGS[@]}"; do
build_config "$CFG_INDEX" "$config" "x64" || true
((++CFG_INDEX))
done
fi
make clean
if [ ${#X32_CONFIGS[@]} -gt 0 ]; then
if [ ${#X64_CONFIGS[@]} -gt 0 ]; then
run_cmd make clean
FORCE_CLEAN=1 # Need this for architecture change
fi
if [ ${#x32_configs[@]} -gt 0 ]; then
echo
echo "==============================================="
echo "Starting 32-bit builds..."
@@ -245,29 +507,15 @@ if [ ${#x32_configs[@]} -gt 0 ]; then
echo
replace_version "x86-64" "i586"
for config in "${x32_configs[@]}"; do
build_config "$config" "x32" || true
CFG_INDEX=0
for config in "${X32_CONFIGS[@]}"; do
build_config "$CFG_INDEX" "$config" "x32" || true
((++CFG_INDEX))
done
fi
total_success=$((x64_success + x32_success))
total_failed=$((x64_failed + x32_failed))
total_builds=$((total_success + total_failed))
echo
echo "============================================"
echo "BUILD SUMMARY"
echo "============================================"
echo "64-bit builds: $x64_success succeeded, $x64_failed failed"
echo "32-bit builds: $x32_success succeeded, $x32_failed failed"
echo "--------------------------------------------"
echo "Total: $total_success succeeded, $total_failed failed (out of $total_builds)"
echo "--------------------------------------------"
echo "You will find all output files of the builds in the 'dist/' folder."
echo "============================================"
echo
if [ $total_failed -gt 0 ]; then
TOTAL_FAILED=$((X64_FAILED + X32_FAILED))
if [ "$TOTAL_FAILED" -gt 0 ]; then
exit 1
else
exit 0

View File

@@ -106,13 +106,17 @@ config BR2_TARGET_ROOTFS_ISO9660_GRUB2_EFI_BOOT_MENU
default "fs/iso9660/efigrub.cfg"
help
Use this option to provide a custom GRUB2 configuration
file (grub.cfg), embedded both in the EFI partition and the
file (grub.cfg), copied both to the EFI partition and the
ISO9660 filesystem EFI-structure (for an EFI bootloader to find).
It will usually contain a "search" and "source" directive to find
the ISO9660 filesystem containing a common (BIOS) GRUB2 configuration.
Alternatively, 'set root=(cd0)' and other such quirks are possible here.
This is specifically for directives required for ISO9660 builds, for
baking an EFI search config into the common GRUB image (often better)
check out instead the GRUB2 setting: BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI
Note that any string __EFI_ID_FILE__ will automatically be
replaced with the BR2_TARGET_ROOTFS_ISO9660_GRUB2_EFI_IDENT_FILE.