#!/bin/sh
# Starts Bottlefield. Without a usable sandbox (a setuid chrome-sandbox, or user namespaces the system allows) Chromium
# refuses to start, so then it goes without one. User namespaces are shut by Ubuntu 23.10+'s AppArmor setting, by older
# Debian kernels (unprivileged_userns_clone 0), or by a namespace limit of 0 (max_user_namespaces).
HERE=$(dirname "$(readlink -f "$0")")
if [ ! -u "$HERE/chrome-sandbox" ]; then
  if [ "$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns 2>/dev/null)" = 1 ] \
    || [ "$(cat /proc/sys/kernel/unprivileged_userns_clone 2>/dev/null)" = 0 ] \
    || [ "$(cat /proc/sys/user/max_user_namespaces 2>/dev/null)" = 0 ]; then
    set -- --no-sandbox "$@"
  fi
fi
exec "$HERE/bottlefield-desktop" "$@"
