From bd4d4cadc83f4a4adc821a3eca4b7533b4601e6e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 15 Jun 2026 23:34:00 +0000 Subject: [PATCH] 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 --- ubuntu-based-kiosk-v1.0.2.sh | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/ubuntu-based-kiosk-v1.0.2.sh b/ubuntu-based-kiosk-v1.0.2.sh index 8b9087c..a68f362 100644 --- a/ubuntu-based-kiosk-v1.0.2.sh +++ b/ubuntu-based-kiosk-v1.0.2.sh @@ -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'