From 4f2435ca350e6b0aff95eadc0f9d2b59721b6a82 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 20 Nov 2025 16:24:31 +0000 Subject: [PATCH] Fix kiosk detection to handle restricted directory permissions The scripts were failing to find the kiosk installation at /home/kiosk/kiosk-app because the /home/kiosk directory has restricted permissions (drwxr-x---), preventing regular users from reading it. Changes in both update_electron.sh and install_kiosk_0.9.2-6.sh: 1. Updated find_kiosk_dir() to use sudo for all file checks - sudo test -f for checking if main.js exists - Prevents "permission denied" errors on restricted directories 2. Added Method 4: Detect from running electron process - Parses ps output to find electron executable path - Extracts app directory from the path - Provides fallback when directory searches fail 3. Updated get_current_electron_version functions - Use sudo test -f to check if package.json exists - Use sudo grep to read package.json and get version - Ensures version detection works with restricted permissions 4. Fixed directory existence checks - Use sudo test -d for checking kiosk directory These changes allow the scripts to: - Find kiosk installations in directories with restricted permissions - Detect installations even when run as a regular user - Work correctly with the standard /home/kiosk setup (drwxr-x---) - Provide better fallback detection using running processes The scripts will now prompt for sudo password when needed to check for files in restricted directories, then continue normally. --- install_kiosk_0.9.2-6.sh | 14 +++++++------- update_electron.sh | 30 ++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/install_kiosk_0.9.2-6.sh b/install_kiosk_0.9.2-6.sh index 6b2701f..749dcde 100755 --- a/install_kiosk_0.9.2-6.sh +++ b/install_kiosk_0.9.2-6.sh @@ -8298,8 +8298,8 @@ manual_electron_update() { echo "══════════════════════════════════════════════════════════" echo "" - # Check if kiosk directory exists - if [ ! -d "$KIOSK_DIR" ]; then + # Check if kiosk directory exists (use sudo in case of restricted permissions) + if ! sudo test -d "$KIOSK_DIR" 2>/dev/null; then log_error "Kiosk directory not found: $KIOSK_DIR" pause return 1 @@ -8309,19 +8309,19 @@ manual_electron_update() { get_current_electron_version_local() { local package_json="$KIOSK_DIR/package.json" - if [ ! -f "$package_json" ]; then + if ! sudo test -f "$package_json" 2>/dev/null; then echo "unknown" return 1 fi - # Try to get version from package.json - local version=$(grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "") + # Try to get version from package.json (use sudo to read) + local version=$(sudo grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "") if [ -z "$version" ]; then # Try to get from installed node_modules local electron_pkg="$KIOSK_DIR/node_modules/electron/package.json" - if [ -f "$electron_pkg" ]; then - version=$(grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown") + if sudo test -f "$electron_pkg" 2>/dev/null; then + version=$(sudo grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown") else version="not installed" fi diff --git a/update_electron.sh b/update_electron.sh index 1263cd8..ac538cd 100755 --- a/update_electron.sh +++ b/update_electron.sh @@ -55,7 +55,8 @@ find_kiosk_dir() { # Method 1: Check default kiosk user home if id "$KIOSK_USER" &>/dev/null; then local kiosk_home=$(eval echo ~$KIOSK_USER) - if [ -f "$kiosk_home/kiosk-app/main.js" ]; then + # Use sudo to check file since /home/kiosk may have restricted permissions + if sudo test -f "$kiosk_home/kiosk-app/main.js" 2>/dev/null; then DETECTED_DIR="$kiosk_home/kiosk-app" fi fi @@ -63,7 +64,8 @@ find_kiosk_dir() { # Method 2: Search all /home directories if [ -z "$DETECTED_DIR" ]; then for user_home in /home/*; do - if [ -f "$user_home/kiosk-app/main.js" ]; then + # Use sudo to check file in case of restricted permissions + if sudo test -f "$user_home/kiosk-app/main.js" 2>/dev/null; then DETECTED_DIR="$user_home/kiosk-app" break fi @@ -74,12 +76,24 @@ find_kiosk_dir() { if [ -z "$DETECTED_DIR" ]; then if systemctl list-units --all kiosk.service 2>/dev/null | grep -q kiosk.service; then local service_dir=$(systemctl show -p WorkingDirectory kiosk.service 2>/dev/null | cut -d= -f2) - if [ -n "$service_dir" ] && [ -f "$service_dir/main.js" ]; then + if [ -n "$service_dir" ] && sudo test -f "$service_dir/main.js" 2>/dev/null; then DETECTED_DIR="$service_dir" fi fi fi + # Method 4: Check for running electron process + if [ -z "$DETECTED_DIR" ]; then + local electron_path=$(ps aux | grep -E "electron.*main.js" | grep -v grep | head -1 | awk '{for(i=11;i<=NF;i++) if($i ~ /^\//) {print $i; exit}}') + if [ -n "$electron_path" ]; then + # Extract directory from electron path (e.g., /home/kiosk/kiosk-app/node_modules/electron/dist/electron -> /home/kiosk/kiosk-app) + local app_dir=$(echo "$electron_path" | sed 's|/node_modules/electron.*||') + if [ -n "$app_dir" ] && sudo test -f "$app_dir/main.js" 2>/dev/null; then + DETECTED_DIR="$app_dir" + fi + fi + fi + echo "$DETECTED_DIR" } @@ -91,19 +105,19 @@ get_current_electron_version() { local kiosk_dir="$1" local package_json="$kiosk_dir/package.json" - if [ ! -f "$package_json" ]; then + if ! sudo test -f "$package_json" 2>/dev/null; then echo "unknown" return 1 fi - # Try to get version from package.json - local version=$(grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "") + # Try to get version from package.json (use sudo to read) + local version=$(sudo grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "") if [ -z "$version" ]; then # Try to get from installed node_modules local electron_pkg="$kiosk_dir/node_modules/electron/package.json" - if [ -f "$electron_pkg" ]; then - version=$(grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown") + if sudo test -f "$electron_pkg" 2>/dev/null; then + version=$(sudo grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown") else version="not installed" fi