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.
This commit is contained in:
Claude
2025-11-20 16:24:31 +00:00
parent 2d05767193
commit 4f2435ca35
2 changed files with 29 additions and 15 deletions
+7 -7
View File
@@ -8298,8 +8298,8 @@ manual_electron_update() {
echo "══════════════════════════════════════════════════════════" echo "══════════════════════════════════════════════════════════"
echo "" echo ""
# Check if kiosk directory exists # Check if kiosk directory exists (use sudo in case of restricted permissions)
if [ ! -d "$KIOSK_DIR" ]; then if ! sudo test -d "$KIOSK_DIR" 2>/dev/null; then
log_error "Kiosk directory not found: $KIOSK_DIR" log_error "Kiosk directory not found: $KIOSK_DIR"
pause pause
return 1 return 1
@@ -8309,19 +8309,19 @@ manual_electron_update() {
get_current_electron_version_local() { get_current_electron_version_local() {
local package_json="$KIOSK_DIR/package.json" local package_json="$KIOSK_DIR/package.json"
if [ ! -f "$package_json" ]; then if ! sudo test -f "$package_json" 2>/dev/null; then
echo "unknown" echo "unknown"
return 1 return 1
fi fi
# Try to get version from package.json # Try to get version from package.json (use sudo to read)
local version=$(grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "") local version=$(sudo grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "")
if [ -z "$version" ]; then if [ -z "$version" ]; then
# Try to get from installed node_modules # Try to get from installed node_modules
local electron_pkg="$KIOSK_DIR/node_modules/electron/package.json" local electron_pkg="$KIOSK_DIR/node_modules/electron/package.json"
if [ -f "$electron_pkg" ]; then if sudo test -f "$electron_pkg" 2>/dev/null; then
version=$(grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown") version=$(sudo grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown")
else else
version="not installed" version="not installed"
fi fi
+22 -8
View File
@@ -55,7 +55,8 @@ find_kiosk_dir() {
# Method 1: Check default kiosk user home # Method 1: Check default kiosk user home
if id "$KIOSK_USER" &>/dev/null; then if id "$KIOSK_USER" &>/dev/null; then
local kiosk_home=$(eval echo ~$KIOSK_USER) 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" DETECTED_DIR="$kiosk_home/kiosk-app"
fi fi
fi fi
@@ -63,7 +64,8 @@ find_kiosk_dir() {
# Method 2: Search all /home directories # Method 2: Search all /home directories
if [ -z "$DETECTED_DIR" ]; then if [ -z "$DETECTED_DIR" ]; then
for user_home in /home/*; do 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" DETECTED_DIR="$user_home/kiosk-app"
break break
fi fi
@@ -74,12 +76,24 @@ find_kiosk_dir() {
if [ -z "$DETECTED_DIR" ]; then if [ -z "$DETECTED_DIR" ]; then
if systemctl list-units --all kiosk.service 2>/dev/null | grep -q kiosk.service; 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) 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" DETECTED_DIR="$service_dir"
fi fi
fi 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" echo "$DETECTED_DIR"
} }
@@ -91,19 +105,19 @@ get_current_electron_version() {
local kiosk_dir="$1" local kiosk_dir="$1"
local package_json="$kiosk_dir/package.json" local package_json="$kiosk_dir/package.json"
if [ ! -f "$package_json" ]; then if ! sudo test -f "$package_json" 2>/dev/null; then
echo "unknown" echo "unknown"
return 1 return 1
fi fi
# Try to get version from package.json # Try to get version from package.json (use sudo to read)
local version=$(grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "") local version=$(sudo grep -oP '"electron"\s*:\s*"\^?\K[0-9.]+' "$package_json" 2>/dev/null || echo "")
if [ -z "$version" ]; then if [ -z "$version" ]; then
# Try to get from installed node_modules # Try to get from installed node_modules
local electron_pkg="$kiosk_dir/node_modules/electron/package.json" local electron_pkg="$kiosk_dir/node_modules/electron/package.json"
if [ -f "$electron_pkg" ]; then if sudo test -f "$electron_pkg" 2>/dev/null; then
version=$(grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown") version=$(sudo grep -oP '"version"\s*:\s*"\K[0-9.]+' "$electron_pkg" 2>/dev/null || echo "unknown")
else else
version="not installed" version="not installed"
fi fi