Fix scripts

This commit is contained in:
2026-04-14 10:54:50 -07:00
parent a238334ae5
commit bc86aafd61
3 changed files with 83 additions and 72 deletions
+2 -9
View File
@@ -53,16 +53,9 @@ run_step() {
return 0 return 0
fi fi
# Step failed - ask what to do # Step failed — prompt retry-or-quit.
# handle_failure exits the whole script on "quit"; otherwise loop retries.
handle_failure "$_step_name" handle_failure "$_step_name"
_decision=$?
if [ $_decision -eq 0 ]; then
# Skip
warn "Skipping: $_step_name"
return 0
fi
# Otherwise retry (loop continues)
done done
} }
+22 -4
View File
@@ -17,6 +17,8 @@ _resolve_chip() {
fi fi
_log=$(mktemp) _log=$(mktemp)
while true; do
printf " ${DIM}\$ sudo flashrom --programmer ch341a_spi${NC}\n" printf " ${DIM}\$ sudo flashrom --programmer ch341a_spi${NC}\n"
sudo flashrom --programmer ch341a_spi >"$_log" 2>&1 sudo flashrom --programmer ch341a_spi >"$_log" 2>&1
_st=$? _st=$?
@@ -43,7 +45,7 @@ _resolve_chip() {
_i=1 _i=1
for _c in $_candidates; do for _c in $_candidates; do
if [ "$_i" = "$_count" ]; then if [ "$_i" = "$_count" ]; then
echo " $_i) $_c ${DIM}(default — newest)${NC}" echo " $_i) $_c (default — newest)"
else else
echo " $_i) $_c" echo " $_i) $_c"
fi fi
@@ -71,12 +73,28 @@ _resolve_chip() {
return 0 return 0
fi fi
# Real failure (no chip, clip bad, etc.) — show the log and fail. # Hard failure no chip detected. Show output and offer re-seat retry.
echo "" echo ""
error "Chip probe failed. flashrom output:" error "Chip probe failed. flashrom output:"
sed 's/^/ /' "$_log" sed 's/^/ /' "$_log"
rm -f "$_log" echo ""
return 1 warn "Most common causes:"
echo " - Clip not seated flush on chip (press down gently, wiggle)"
echo " - Pin 1 misaligned (red ribbon wire ↔ chip dot/notch)"
echo " - Clipped onto the wrong chip (try the other one, then switch back)"
echo " - Residual laptop power (remove main battery + CMOS coin cell)"
echo " - Cheap SOIC-8 clips can make intermittent contact"
echo ""
echo " 1) Re-seat clip and retry"
echo " 2) Abort"
echo ""
printf "${CYAN}Choice [1-2]:${NC} "
read -r _choice
case "$_choice" in
1) continue ;;
*) rm -f "$_log"; return 1 ;;
esac
done
} }
# Read a chip with inline retry on failure. # Read a chip with inline retry on failure.
+10 -10
View File
@@ -12,11 +12,11 @@ BOLD='\033[1m'
DIM='\033[2m' DIM='\033[2m'
NC='\033[0m' NC='\033[0m'
# Logging # Logging — %b interprets backslash escapes so inline ${BOLD}, ${DIM} etc. work.
info() { printf "${BLUE}[*]${NC} %s\n" "$1"; } info() { printf "${BLUE}[*]${NC} %b\n" "$1"; }
warn() { printf "${YELLOW}[!]${NC} %s\n" "$1"; } warn() { printf "${YELLOW}[!]${NC} %b\n" "$1"; }
error() { printf "${RED}[x]${NC} %s\n" "$1"; } error() { printf "${RED}[x]${NC} %b\n" "$1"; }
success() { printf "${GREEN}[+]${NC} %s\n" "$1"; } success() { printf "${GREEN}[+]${NC} %b\n" "$1"; }
# Print a section header # Print a section header
section() { section() {
@@ -188,20 +188,20 @@ show_image() {
[ -n "$_caption" ] && info "$_caption" [ -n "$_caption" ] && info "$_caption"
} }
# Handle step failure - ask user how to proceed # Handle step failure — retry or quit only.
# Skipping is deliberately not offered: most steps (extract/flash/revert)
# are irreversible or a skip will brick the board downstream.
handle_failure() { handle_failure() {
echo "" echo ""
error "Step failed: $1" error "Step failed: $1"
echo "" echo ""
echo " 1) Retry this step" echo " 1) Retry this step"
echo " 2) Skip and continue" echo " 2) Quit"
echo " 3) Quit"
echo "" echo ""
printf "${CYAN}Choice [1-3]:${NC} " printf "${CYAN}Choice [1-2]:${NC} "
read -r _choice read -r _choice
case "$_choice" in case "$_choice" in
1) return 1 ;; # Signal retry 1) return 1 ;; # Signal retry
2) return 0 ;; # Signal skip
*) exit 1 ;; *) exit 1 ;;
esac esac
} }