mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 22:14:01 +01:00
check_file_length.sh required a dot in the filename, so every
extensionless executable was silently uncapped. is_source_file() now
reads the first two bytes and accepts a shebang, which catches real
scripts while still skipping data files like i3/config.
That immediately surfaced boot_recovery/boot-repair at 756 lines --
three times the largest capped shell file in the repo, uncapped purely
because its name has no dot in it. Split along its own section markers
into lib/{discovery,repair_fs,repair_kernel,modes}.sh, leaving the entry
script at 218.
The report block stays inline on purpose. It is top-level code with exit
calls rather than function definitions, and sourcing it changed control
flow: 30 of 42 tests failed. That is recorded in the lib headers so the
next reader does not retry it.
No vmbox pass for this one, deliberately. boot-repair is UEFI/ESP tooling
and the guest is BIOS/GRUB, so a sandbox green would be actively
misleading -- the vmbox skill says so itself. The evidence is the fixture
suite, which drives the real script against synthetic root trees: 42
passed before, 42 passed after.
verify_shell_split.sh reports 31 of 32 functions byte-identical. The one
difference is clean_shadow_files, where quoting $ESP_MOUNTPOINT fixed a
genuine SC2086 that only became visible once the function left the
monolith -- shellcheck could no longer see the readonly declaration and
stopped assuming the expansion was safe.
lib/tests/run_all.sh delegates to that same suite rather than standing up
a second, weaker harness: these libraries need the entry script's strict
mode and globals, so testing them in isolation would test a fiction.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
79 lines
2.3 KiB
Bash
Executable File
79 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# The two run modes: preflight and the full check sweep.
|
|
#
|
|
# Sourced by boot-repair, not executed. Split out of it verbatim to bring the
|
|
# entry script under the 250-line cap; it inherits the caller's strict mode,
|
|
# its $ROOT/$MODE globals and the output helpers defined there.
|
|
#
|
|
# Only function DEFINITIONS live here. The report block at the end of
|
|
# boot-repair stays inline on purpose: it is top-level code with `exit` calls,
|
|
# and sourcing it changes control flow -- tried it, 30 of 42 tests failed.
|
|
#
|
|
# shellcheck shell=bash
|
|
# shellcheck source=../boot-repair
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Modes
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# PreTransaction gate: refuse a kernel upgrade when the ESP is not mounted,
|
|
# because that upgrade would write the kernel into the root filesystem instead.
|
|
run_preflight() {
|
|
if boot_is_mounted; then
|
|
printf 'boot-repair: ESP mounted at %s — proceeding.\n' "$ESP_MOUNTPOINT"
|
|
exit 0
|
|
fi
|
|
cat >&2 <<EOF
|
|
|
|
==> boot-repair: ABORTING TRANSACTION
|
|
|
|
$ESP_MOUNTPOINT is not mounted. Installing a kernel now would write it into
|
|
the root filesystem, leaving the firmware booting a stale image whose
|
|
modules this upgrade is about to delete.
|
|
|
|
Fix it, then retry:
|
|
sudo mount $ESP_MOUNTPOINT
|
|
sudo $SCRIPT_NAME
|
|
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
run_checks() {
|
|
local kver
|
|
|
|
ensure_root_writable
|
|
|
|
msg "Kernel / ESP consistency"
|
|
check_fstab_options || true
|
|
clean_shadow_files || true
|
|
ensure_vfat || true
|
|
mount_esp || true
|
|
|
|
if ! kver="$(newest_complete_kernel)"; then
|
|
problem "no complete kernel module tree found under $(rpath /usr/lib/modules)"
|
|
msg ""
|
|
msg " Recover the kernel package first (offline, from cache):"
|
|
msg " pacman -U /var/cache/pacman/pkg/linux-*.pkg.tar.zst"
|
|
return 1
|
|
fi
|
|
info "target kernel: $kver"
|
|
|
|
ensure_depmod "$kver" || true
|
|
|
|
# Only meaningful once the ESP is actually mounted; otherwise these would
|
|
# write into the root filesystem — the very bug being repaired.
|
|
if boot_is_mounted || ! is_live; then
|
|
sync_kernel_image "$kver" || true
|
|
rebuild_initramfs "$kver" || true
|
|
else
|
|
problem "ESP still unmounted — cannot sync the kernel image"
|
|
fi
|
|
|
|
msg ""
|
|
msg "Upgrade safety"
|
|
check_parallel_downloads || true
|
|
return 0
|
|
}
|