#!/bin/sh # Coreboot T440p Interactive Installer # https://timmypidashev.dev/blog/thinkpad-t440p-coreboot-guide set -e # Resolve script directory SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Source dependencies . "$SCRIPT_DIR/utils.sh" . "$SCRIPT_DIR/config.sh" . "$SCRIPT_DIR/system.sh" # Source all step scripts for _step_file in "$SCRIPT_DIR/steps/"*.sh; do [ -f "$_step_file" ] && . "$_step_file" done # Disable set -e after sourcing (we handle errors per-step) set +e # --- Banner --- show_banner() { printf "${BOLD}${PURPLE}" echo "" echo " ╔════════════════════════════════════════════════════╗" echo " ║ Coreboot T440p Interactive Installer ║" echo " ╚════════════════════════════════════════════════════╝" printf "${NC}" echo "" echo " Guide: timmypidashev.dev/blog/thinkpad-t440p-coreboot-guide" echo "" } # --- Step runner --- # Run a step function with retry/skip handling run_step() { _step_num="$1" _step_name="$2" _step_func="$3" printf "\n${BOLD}${CYAN}[Step %s/12] %s${NC}\n" "$_step_num" "$_step_name" echo "" while true; do "$_step_func" _rc=$? if [ $_rc -eq 0 ]; then return 0 fi # Step failed — prompt retry-or-quit. # handle_failure exits the whole script on "quit"; otherwise loop retries. handle_failure "$_step_name" done } # --- Main flow --- # Validate a step number (1-12). Coerces invalid input to 1. _sanitize_step() { case "$1" in ''|*[!0-9]*) echo 1; return ;; esac if [ "$1" -lt 1 ] || [ "$1" -gt 12 ]; then echo 1 else echo "$1" fi } run_full_install() { _start=$(_sanitize_step "${1:-1}") [ "$_start" -le 1 ] && run_step 1 "Install Dependencies" install_dependencies [ "$_start" -le 2 ] && run_step 2 "Connect CH341A Programmer" step_attach_ch341a [ "$_start" -le 3 ] && run_step 3 "Extract Original BIOS" step_extract_bios [ "$_start" -le 4 ] && run_step 4 "Verify BIOS Backups" step_backup_bios [ "$_start" -le 5 ] && run_step 5 "Combine BIOS Images" step_combine_bios [ "$_start" -le 6 ] && run_step 6 "Clone Coreboot Repository" step_clone_coreboot [ "$_start" -le 7 ] && run_step 7 "Build ifdtool & Extract Blobs" step_build_ifdtool [ "$_start" -le 8 ] && run_step 8 "Build cbfstool" step_build_cbfstool [ "$_start" -le 9 ] && run_step 9 "Obtain mrc.bin" step_build_peppy [ "$_start" -le 10 ] && run_step 10 "Configure Coreboot" step_configure [ "$_start" -le 11 ] && run_step 11 "Build Coreboot" step_build_bios [ "$_start" -le 12 ] && run_step 12 "Flash Coreboot" step_flash_bios echo "" printf "${BOLD}${GREEN}" echo " ╔════════════════════════════════════════════════════╗" echo " ║ All steps complete! ║" echo " ╚════════════════════════════════════════════════════╝" printf "${NC}\n" } # --- CLI --- print_usage() { cat <