#!/bin/sh
# SPDX-FileCopyrightText: 2018-2019 Harald Sitter <sitter@kde.org>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL

# Force Plasma themeing
export QT_PLATFORM_PLUGIN=kde
export KDE_FULL_SESSION=TRUE
export KDE_SESSION_VERSION=6
export QT_QPA_PLATFORMTHEME=kde

export XDG_DATA_DIRS=/calamares/desktop:$XDG_DATA_DIRS:/usr/share
export XDG_CONFIG_DIRS=/calamares/desktop:$XDG_CONFIG_DIRS:/etc/xdg

if [ -f /usr/bin/startplasmamobile ]; then
  echo "Enabling Calamares for Plasma Mobile"
  export XDG_DATA_DIRS=/calamares/mobile:$XDG_DATA_DIRS
  export XDG_CONFIG_DIRS=/calamares/mobile:$XDG_CONFIG_DIRS
fi

if [ -f /usr/bin/plasma-bigscreen-wayland ]; then
  echo "Enabling Calamares for Plasma Bigscreen"
  export XDG_DATA_DIRS=/calamares/bigscreen:$XDG_DATA_DIRS
  export XDG_CONFIG_DIRS=/calamares/bigscreen:$XDG_CONFIG_DIRS
fi

# Pinebook is not installed by default and only available on arm. Stack it on
# top when it is available.
if [ -d /calamares/pinebook ]; then
  echo "Enabling pinebook mode"
  export XDG_DATA_DIRS=/calamares/pinebook:$XDG_DATA_DIRS
  export XDG_CONFIG_DIRS=/calamares/pinebook:$XDG_CONFIG_DIRS
else
  if [ "$OEM_MODE" != "" ] || grep -Fq 'oem-config/enable=true' /proc/cmdline; then
    echo "Enabling oem-prepare mode"
    export XDG_DATA_DIRS=/calamares/oem-prepare:$XDG_DATA_DIRS
    export XDG_CONFIG_DIRS=/calamares/oem-prepare:$XDG_CONFIG_DIRS
  elif [ ! -e /etc/calamares-oem-done ] && [ -e /var/log/installer/oem-id ]; then
    echo "Enabling oem-config mode"
    export XDG_DATA_DIRS=/calamares/oem-config:$XDG_DATA_DIRS
    export XDG_CONFIG_DIRS=/calamares/oem-config:$XDG_CONFIG_DIRS
  else
    echo "Not enabling extra modes"
  fi
fi

swapoff -a || true

exec /usr/bin/_neon.calamares --xdg-config "$@"
