#!/usr/bin/env sh

# SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

# shellcheck shell=sh

# Environment generator for both system and user systemd managers.
# Update PATH and XDG_DATA_DIRS, then print them for systemd to import.
# Login sessions also need the profile.d/Xsession.d script because their
# startup scripts may reset PATH and import it back into the user manager.

source_script="/usr/lib/linglong/generate-path.sh"
[ -r "${source_script}" ] && . "${source_script}"

source_script="/usr/lib/linglong/generate-xdg-data-dirs.sh"

# Source the script and export XDG_DATA_DIRS if successful
[ -r "${source_script}" ] && . "${source_script}"

# !!!systemd requires environment variables to be printed to standard output!!!
# https://www.freedesktop.org/software/systemd/man/latest/systemd.environment-generator.html
[ -n "${PATH}" ] && echo "PATH=${PATH}"
[ -n "${XDG_DATA_DIRS}" ] && echo "XDG_DATA_DIRS=${XDG_DATA_DIRS}"
