Fix Electron binary extraction: chown dist/ before extracting as kiosk user

The previous fix incorrectly ran unzip as root, which fails because
/home/kiosk is not accessible to root. The kiosk user is the right
actor for the extraction, but two things blocked it:

1. node_modules/electron/dist/ can be owned by root when npm's electron
   postinstall runs with --unsafe-perm, so the kiosk user gets
   'Permission denied' trying to write there. Fix: sudo chown -R the
   electron directory to the kiosk user before extracting.

2. With set -euo pipefail active (upgrade call had no || guard), a
   failed unzip or chmod would abort the script silently before the
   diagnostic error messages could print. Fix: add || true to both
   commands so the function always reaches the explicit -f check which
   prints the real error and returns 1. The upgrade call already has
   || { log_error ...; return 1; } from the previous commit.

https://claude.ai/code/session_01VQ13Fwq4MXxwThLfCXBeGr
This commit is contained in:
Claude
2026-06-16 17:17:37 +00:00
parent 670b32f53c
commit 43266a4cf0
+6 -6
View File
@@ -11099,12 +11099,12 @@ install_electron_binary() {
tmp_zip=$(mktemp --suffix=.zip)
if wget --timeout=300 --tries=3 --show-progress -O "$tmp_zip" "$electron_url" 2>&1; then
command -v unzip >/dev/null 2>&1 || sudo apt install -y unzip
# Run as root so we can write regardless of who owns node_modules/electron/dist/
# (npm postinstall may create it as root when --unsafe-perm is used)
mkdir -p "$KIOSK_DIR/node_modules/electron/dist"
unzip -o "$tmp_zip" -d "$KIOSK_DIR/node_modules/electron/dist/"
chown -R "$KIOSK_USER:$KIOSK_USER" "$KIOSK_DIR/node_modules/electron/dist/"
chmod +x "$electron_bin"
# Fix ownership first so the kiosk user can write into the directory
# (npm postinstall with --unsafe-perm can leave dist/ owned by root)
sudo chown -R "$KIOSK_USER:$KIOSK_USER" "$KIOSK_DIR/node_modules/electron/" 2>/dev/null || true
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/" || true
sudo -u "$KIOSK_USER" chmod +x "$electron_bin" || true
fi
rm -f "$tmp_zip"
fi