#!/usr/bin/env bash
# Installed sessions authenticate through the ordinary tty login.
set -u

if [[ $EUID -eq 0 ]]; then
	printf 'forgeOS: log in as your normal user to start the desktop.\n' >&2
	exit 1
fi
if systemd-detect-virt -q --vm; then
	if [[ ! -d /dev/dri ]] || [[ -z $(find /dev/dri -maxdepth 1 -type c -name 'renderD*' -print -quit) ]]; then
		printf 'forgeOS: This VM has no DRM render node; staying in the console.\n'
		exit 0
	fi
fi
export XDG_SESSION_TYPE=wayland
export XDG_CURRENT_DESKTOP=Hyprland
export XDG_SESSION_DESKTOP=Hyprland
if [[ -z ${AQ_DRM_DEVICES:-} ]]; then
	graphics_devices=$(/usr/lib/forge/graphics-devices)
	if [[ -n $graphics_devices ]]; then
		export AQ_DRM_DEVICES="$graphics_devices"
	fi
fi
/usr/bin/start-hyprland
