#!/bin/sh

# Check if unprivileged user namespaces are restricted by AppArmor
if [ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ] && [ "$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns)" = "1" ]; then
    echo "ERROR: This application requires unprivileged user namespaces, which are restricted on this system."
    echo ""
    echo "To run this application, you have three options:"
    echo ""
    echo "1. Install the .deb package version instead (recommended):"
    echo "   Visit https://update.rekord.cloud/releases/groof/latest/"
    echo ""
    echo "2. Or temporarily disable the restriction (must be done after each reboot):"
    echo "   sudo bash -c 'echo 0 > /proc/sys/kernel/apparmor_restrict_unprivileged_userns'"
    echo ""
    echo "3. Or permanently disable the restriction:"
    echo "   sudo bash -c 'echo kernel.apparmor_restrict_unprivileged_userns=0 >> /etc/sysctl.d/60-apparmor-namespace.conf'"
    echo ""
    exit 1
fi

# Execute the actual binary
exec "$(dirname "$0")"/groof.bin "$@"
