{{- if (eq .host.distro.family "linux") -}}
#!/usr/bin/env bash
# @file Global Profile Setup
# @brief Configures `/etc/environment` to include environment variables that should be applied globally and adds a `/etc/zshenv` file
# @description
#     This script modifies the `/etc/environment` file on Linux devices to include:
#
#     * `export QT_STYLE_OVERRIDE=kvantum-dark` which is required for the Linux GNOME / KDE themeing that relies on Kvantum.
#
#     It also copies the `~/.config/shell/exports.sh` file to `/etc/zshenv` so that non-interactive ZSH sessions have all of the same
#     environment PATH variables as interactive sessions. This was initially required to make Cakebrew work on macOS.

{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}

### Ensure QT_STYLE_OVERRIDE is set in /etc/environment
logg info 'Ensuring QT_STYLE_OVERRIDE is set in /etc/environment'
if cat /etc/environment | grep QT_STYLE_OVERRIDE > /dev/null; then
  sudo sed -i 's/.*QT_STYLE_OVERRIDE.*/export QT_STYLE_OVERRIDE=kvantum-dark/' /etc/environment
  logg info 'Updated QT_STYLE_OVERRIDE in /etc/environment'
else
  echo 'export QT_STYLE_OVERRIDE=kvantum-dark' | sudo tee -a /etc/environment
  logg info 'Added QT_STYLE_OVERRIDE to /etc/environment'
fi

### Ensure /etc/zshenv is populated
# No equivalent type of file for Bash
logg info "Copying ${XDG_CONFIG_HOME:-$HOME/.config}/shell/exports.sh to /etc/zshenv" && sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/exports.sh" /etc/zshenv

{{ end -}}
