fix: robust Electron binary download with timeouts, retry, and wget fallback

The ~120MB Electron binary download was silently failing because npm's
default 60s fetch timeout is too short on slower connections.

Changes to step 17/27:
- Set npm fetch-timeout to 600s and retries to 5 before running npm install
- If binary still missing after npm install, retry via install.js with
  ELECTRON_FORCE_DOWNLOAD=true
- If still missing, fall back to direct wget download of the exact
  versioned zip from GitHub releases (300s timeout, 3 tries, shows progress)
- Exit 1 with clear message if all three attempts fail
- Log chrome-sandbox permission step for visibility

https://claude.ai/code/session_01EyjEQLWbTXcZgbMDarf7NU
This commit is contained in:
Claude
2026-06-15 23:34:00 +00:00
parent 2556863129
commit bd4d4cadc8
+36 -3
View File
@@ -7259,17 +7259,49 @@ PKGJSON
echo "[17/27] Installing Electron packages..."
echo "Note: npm may show deprecation warnings (safe to ignore)"
echo "Note: Electron binary is ~120MB — download may take several minutes"
# Increase npm fetch timeouts before install (default 60s is too short for ~120MB)
sudo -u "$KIOSK_USER" bash -lc "
npm config set fetch-timeout 600000
npm config set fetch-retries 5
npm config set fetch-retry-mintimeout 30000
npm config set fetch-retry-maxtimeout 300000
"
sudo -u "$KIOSK_USER" bash -lc "cd '$KIOSK_DIR' && npm install --unsafe-perm"
# Verify electron binary downloaded (npm install succeeds even if the binary download fails)
local electron_bin="$KIOSK_DIR/node_modules/electron/dist/electron"
if [[ ! -f "$electron_bin" ]]; then
log_warning "Electron binary not found after npm install — retrying download..."
log_warning "Electron binary not found after npm install — retrying via install.js..."
sudo -u "$KIOSK_USER" bash -lc "cd '$KIOSK_DIR' && ELECTRON_FORCE_DOWNLOAD=true node node_modules/electron/install.js" || true
fi
# Last resort: direct wget download of the binary zip
if [[ ! -f "$electron_bin" ]]; then
log_error "Electron binary download failed. Check network connectivity and retry:"
log_error " cd $KIOSK_DIR && sudo -u $KIOSK_USER ELECTRON_FORCE_DOWNLOAD=true npm install electron --unsafe-perm"
log_warning "Attempting direct wget download of Electron binary..."
local electron_ver
electron_ver=$(sudo -u "$KIOSK_USER" node -e \
"try{console.log(require('$KIOSK_DIR/node_modules/electron/package.json').version)}catch(e){}" 2>/dev/null)
if [[ -n "$electron_ver" ]]; then
local electron_url="https://github.com/electron/electron/releases/download/v${electron_ver}/electron-v${electron_ver}-linux-x64.zip"
log_info "Downloading Electron v${electron_ver} directly (~120MB)..."
local tmp_zip
tmp_zip=$(mktemp --suffix=.zip)
if wget --timeout=300 --tries=3 --show-progress -O "$tmp_zip" "$electron_url" 2>&1; then
sudo -u "$KIOSK_USER" mkdir -p "$KIOSK_DIR/node_modules/electron/dist"
sudo -u "$KIOSK_USER" unzip -o "$tmp_zip" -d "$KIOSK_DIR/node_modules/electron/dist/"
sudo -u "$KIOSK_USER" chmod +x "$electron_bin"
fi
rm -f "$tmp_zip"
fi
fi
if [[ ! -f "$electron_bin" ]]; then
log_error "Electron binary download failed after all attempts."
log_error "Check your internet connection and re-run the installer."
log_error "The binary is downloaded from: https://github.com/electron/electron/releases"
exit 1
fi
log_success "Electron binary verified"
@@ -7278,6 +7310,7 @@ PKGJSON
if [[ -f "$sandbox" ]]; then
sudo chown root:root "$sandbox"
sudo chmod 4755 "$sandbox"
log_success "Chrome sandbox permissions set"
fi
sudo -u "$KIOSK_USER" tee "$KIOSK_DIR/start.sh" > /dev/null <<'LAUNCHER'