#!/bin/bash
INSTALL_DIR="/opt/wallie-desktop"

if [ "$(id -u)" = "0" ]; then
  echo "Error: Do not run Wallie with sudo. Run as your normal user:" >&2
  echo "  wallie-desktop" >&2
  exit 1
fi

if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
  echo "Error: No display server found. Wallie requires a graphical session." >&2
  exit 1
fi

MISSING=$(ldd "$INSTALL_DIR/wallie" 2>/dev/null | grep "not found" | head -5)
if [ -n "$MISSING" ]; then
  echo "Error: Missing system libraries:" >&2
  echo "$MISSING" >&2
  echo "" >&2
  echo "Try: sudo apt install -f" >&2
  exit 1
fi

exec "$INSTALL_DIR/wallie" "$@"
