#!/bin/sh
set -eu
app_directory=$(CDPATH= cd -- "$(dirname -- "$(readlink -f -- "$0")")" && pwd)
if [ -n "${APPIMAGE:-}" ] && [ "$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns 2>/dev/null || true)" = 1 ]; then
  message='Onwarder cannot open this AppImage with the sandbox enabled on this system. On Ubuntu 24.04 and later, install the .deb from onwarder.com instead. Your library will stay on your computer.'
  printf '%s\n' "$message" >&2
  if [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then
    if command -v zenity >/dev/null 2>&1; then
      zenity --error --title='Install Onwarder for Ubuntu' --text="$message" || true
    elif command -v kdialog >/dev/null 2>&1; then
      kdialog --error "$message" --title 'Install Onwarder for Ubuntu' || true
    elif command -v xmessage >/dev/null 2>&1; then
      xmessage -center -title 'Install Onwarder for Ubuntu' -buttons OK:0 -default OK "$message" || true
    fi
  fi
  exit 78
fi
exec "$app_directory/onwarder-bin" "$@"
