Until now ./install.sh only managed an already-installed kiosk; ubuntu-based-kiosk.sh was still the only path from a bare Ubuntu Server box to a running one. install.sh now provisions from scratch too: packages, kiosk user, Node.js/Electron, LightDM+Openbox autologin, audio/video/HDMI/power-button hardware setup, and the firewall, then hands off to the already-migrated Core Settings/Advanced menus for initial configuration instead of reimplementing that logic again. - lib/provision.sh: the new provisioning flow, built mostly by calling existing menus (core_settings_menu, emergency hotspot, virtual consoles) - cuts it to ~300 lines against the legacy script's ~4,000-line first_time_install(). - lib/electron.sh: electron_install_binary() extracted out of menus/advanced_electron.sh so provisioning and the existing "Fix blank screen" action share one implementation. - kiosk-app/ and provision/files/: the Electron app source and every system template file, extracted byte-for-byte out of ubuntu-based-kiosk.sh's heredocs into real files. - Found and fixed a bash set -e gotcha along the way: testing a multi-statement function as an if-condition (`if ! some_func; then`) silently exempts everything inside that function from set -e for the duration of the call. Fixed in the new provisioning code and in menus/advanced_electron.sh's pre-existing repair action, which had the same shape. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VfsFSoRqfbRG7XAg5RoE7e
59 lines
3.0 KiB
Bash
59 lines
3.0 KiB
Bash
#!/bin/bash
|
|
################################################################################
|
|
# lib/electron.sh - Electron binary install/repair, shared between fresh
|
|
# provisioning (lib/provision.sh) and ongoing maintenance
|
|
# (menus/advanced_electron.sh's "Fix blank screen" action) - the exact
|
|
# same repair sequence applies whether the binary never downloaded during
|
|
# `npm install` or went missing later.
|
|
#
|
|
# Depends on: lib/config.sh being sourced first (for $KIOSK_DIR/$KIOSK_USER).
|
|
################################################################################
|
|
|
|
# Re-verify/download the Electron binary and fix chrome-sandbox
|
|
# permissions, without touching package.json or reinstalling anything else.
|
|
electron_install_binary() {
|
|
local electron_bin="$KIOSK_DIR/node_modules/electron/dist/electron"
|
|
|
|
if ! sudo -u "$KIOSK_USER" test -f "$electron_bin"; then
|
|
log_warning "Electron binary missing - 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
|
|
|
|
if ! sudo -u "$KIOSK_USER" test -f "$electron_bin"; then
|
|
log_warning "Attempting direct download of Electron binary (~120MB)..."
|
|
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 || true)
|
|
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..."
|
|
local tmp_zip
|
|
tmp_zip=$(mktemp --suffix=.zip)
|
|
if wget --timeout=300 --tries=3 -O "$tmp_zip" "$electron_url"; then
|
|
command -v unzip &>/dev/null || sudo apt install -y unzip
|
|
chmod 644 "$tmp_zip"
|
|
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
|
|
fi
|
|
|
|
if ! sudo -u "$KIOSK_USER" test -f "$electron_bin"; then
|
|
log_error "Electron binary download failed after all attempts."
|
|
log_error "Check your internet connection and try again."
|
|
return 1
|
|
fi
|
|
log_success "Electron binary verified"
|
|
|
|
# chrome-sandbox MUST be owned by root and setuid, or Electron shows a blank screen.
|
|
local sandbox="$KIOSK_DIR/node_modules/electron/dist/chrome-sandbox"
|
|
if sudo -u "$KIOSK_USER" test -f "$sandbox"; then
|
|
sudo chown root:root "$sandbox"
|
|
sudo chmod 4755 "$sandbox"
|
|
log_success "Chrome sandbox permissions set (required for display)"
|
|
fi
|
|
}
|