#!/usr/bin/env bash

source /etc/default/gamescope-session

IMAGE_INFO="/usr/share/ublue-os/image-info.json"
BASE_IMAGE_NAME=$(jq -r '."base-image-name"' < $IMAGE_INFO)

USER=$(id -nu 1000)

# SteamOS autologin SDDM config
AUTOLOGIN_CONF='/etc/sddm.conf.d/zz-steamos-autologin.conf'

# Configure autologin if Steam has been updated
if [[ -f /var/home/$USER/.local/share/Steam/ubuntu12_32/steamui.so ]]; then
  {
    echo "[Autologin]"
    echo "Session=${GAMESCOPE_SESSION}.desktop"
  } > "$AUTOLOGIN_CONF"
fi

if [[ $BASE_IMAGE_NAME = "kinoite" ]]; then
  sudo -Eu $USER qdbus org.kde.Shutdown /Shutdown org.kde.Shutdown.logout
elif [[ $BASE_IMAGE_NAME = "silverblue" ]]; then
  sudo -Eu $USER gnome-session-quit --logout --no-prompt
fi
