2022-07-12 11:55:53 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-01-08 09:09:55 +11:00
|
|
|
set -e
|
|
|
|
|
|
2022-07-12 11:55:53 -04:00
|
|
|
# From: https://people.debian.org/~mpitt/systemd.conf-2016-graphical-session.pdf
|
|
|
|
|
|
2024-01-09 15:50:00 +11:00
|
|
|
if command -v systemctl >/dev/null; then
|
|
|
|
|
# robustness: if the previous graphical session left some failed units,
|
|
|
|
|
# reset them so that they don't break this startup
|
|
|
|
|
for unit in $(systemctl --user --no-legend --state=failed --plain list-units | cut -f1 -d' '); do
|
|
|
|
|
partof="$(systemctl --user show -p PartOf --value "$unit")"
|
|
|
|
|
for target in cosmic-session.target graphical-session.target; do
|
|
|
|
|
if [ "$partof" = "$target" ]; then
|
|
|
|
|
systemctl --user reset-failed "$unit"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
2022-07-12 11:55:53 -04:00
|
|
|
done
|
2024-01-09 15:50:00 +11:00
|
|
|
fi
|
2022-07-12 11:55:53 -04:00
|
|
|
|
2024-01-08 09:09:55 +11:00
|
|
|
# use the user's preferred shell to acquire environment variables
|
|
|
|
|
# see: https://github.com/pop-os/cosmic-session/issues/23
|
|
|
|
|
if [ -n "${SHELL}" ]; then
|
|
|
|
|
# --in-login-shell: our flag to indicate that we don't need to recurse any further
|
|
|
|
|
if [ "${1}" != "--in-login-shell" ]; then
|
|
|
|
|
# `exec -l`: like `login`, prefixes $SHELL with a hyphen to start a login shell
|
|
|
|
|
exec bash -c "exec -l '${SHELL}' -c '${0} --in-login-shell'"
|
|
|
|
|
fi
|
2022-09-23 10:39:43 -06:00
|
|
|
fi
|
|
|
|
|
|
2023-12-22 10:34:47 -05:00
|
|
|
export XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:=COSMIC}"
|
2026-04-12 09:47:59 +02:00
|
|
|
export XDG_SESSION_DESKTOP="${XDG_SESSION_DESKTOP:=COSMIC}"
|
2022-07-12 11:55:53 -04:00
|
|
|
export XDG_SESSION_TYPE="${XDG_SESSION_TYPE:=wayland}"
|
2022-10-24 14:03:45 -04:00
|
|
|
export _JAVA_AWT_WM_NONREPARENTING=1
|
2023-01-25 11:07:56 -05:00
|
|
|
export GDK_BACKEND=wayland,x11
|
|
|
|
|
export MOZ_ENABLE_WAYLAND=1
|
2023-12-19 21:50:47 +01:00
|
|
|
export QT_QPA_PLATFORM="wayland;xcb"
|
2024-08-27 17:27:09 +02:00
|
|
|
export QT_AUTO_SCREEN_SCALE_FACTOR=1
|
|
|
|
|
export QT_ENABLE_HIGHDPI_SCALING=1
|
2024-11-21 16:50:08 +01:00
|
|
|
export DCONF_PROFILE=cosmic
|
2022-07-12 11:55:53 -04:00
|
|
|
|
2026-02-20 20:36:45 +00:00
|
|
|
# Set the QT platform theme to CuteCosmic. Fallback to qt6ct if CuteCosmic is not installed.
|
2026-03-11 00:45:10 +00:00
|
|
|
if [ -z "$QT_QPA_PLATFORMTHEME" ]; then
|
|
|
|
|
export QT_QPA_PLATFORMTHEME=cosmic
|
|
|
|
|
for QT_PLUGIN_PATH in /usr/lib{*,/*}/qt6/plugins; do
|
|
|
|
|
if [ -f "${QT_PLUGIN_PATH}/platformthemes/libcutecosmictheme.so" ]; then
|
|
|
|
|
# CuteCosmic found, no need for a fallback.
|
|
|
|
|
export QT_QPA_PLATFORMTHEME=cosmic
|
|
|
|
|
break
|
2026-03-14 21:16:58 +00:00
|
|
|
elif [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt6ct.so" ] || [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt5ct.so" ]; then
|
2026-03-11 00:45:10 +00:00
|
|
|
# Fallback to qt6ct, but keep looking for CuteCosmic.
|
2026-03-14 21:16:58 +00:00
|
|
|
# Note that "qt5ct" is compatible with both qt5ct and qt6ct.
|
|
|
|
|
export QT_QPA_PLATFORMTHEME=qt5ct
|
2026-03-11 00:45:10 +00:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
2026-02-20 20:36:45 +00:00
|
|
|
|
2025-08-20 18:03:55 +00:00
|
|
|
# Start gnome keyring components if the daemon is active
|
|
|
|
|
# -> check if /run/user/$UID/keyring exists
|
|
|
|
|
if [ -d "/run/user/$(id -u)/keyring" ]; then
|
|
|
|
|
|
2025-09-05 13:35:34 -06:00
|
|
|
# Use PATH lookup instead of hardcoding /usr/bin
|
|
|
|
|
if command -v gnome-keyring-daemon >/dev/null 2>&1; then
|
2025-09-12 17:35:55 -04:00
|
|
|
eval "$(gnome-keyring-daemon --start --components=pkcs11,secrets,ssh > /dev/null 2>&1)"
|
2025-09-05 13:35:34 -06:00
|
|
|
else
|
|
|
|
|
echo "gnome-keyring-daemon not found in PATH" >&2
|
|
|
|
|
fi
|
2025-08-20 18:03:55 +00:00
|
|
|
|
2026-01-20 23:08:57 +05:30
|
|
|
# Only set SSH_AUTH_SOCK if the socket actually exists. Either
|
|
|
|
|
# set the correct one, or don't set one at all. Don't set the
|
|
|
|
|
# wrong value.
|
|
|
|
|
if [ -S "/run/user/$(id -u)/gcr/ssh" ]; then
|
|
|
|
|
export SSH_AUTH_SOCK="/run/user/$(id -u)/gcr/ssh"
|
|
|
|
|
elif [ -S "/run/user/$(id -u)/keyring/ssh" ]; then
|
|
|
|
|
export SSH_AUTH_SOCK="/run/user/$(id -u)/keyring/ssh"
|
|
|
|
|
fi
|
2025-08-20 18:03:55 +00:00
|
|
|
fi
|
2025-08-29 16:44:53 +02:00
|
|
|
|
2026-01-06 06:26:44 +05:30
|
|
|
if command -v systemctl >/dev/null; then
|
2026-01-14 19:55:03 +05:30
|
|
|
# Import some variables that we explicitly want to have available
|
|
|
|
|
# in the user session.
|
2026-01-06 06:26:44 +05:30
|
|
|
systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP DCONF_PROFILE SSH_AUTH_SOCK
|
2026-01-14 19:55:03 +05:30
|
|
|
|
|
|
|
|
# For environment variables already imported into the user's
|
|
|
|
|
# session, if the value imported differs from the value in this
|
|
|
|
|
# environment, update it.
|
2026-02-03 16:37:32 +01:00
|
|
|
mapfile -t existing_env_vars < <(systemctl --user show-environment)
|
2026-01-14 19:55:03 +05:30
|
|
|
for env_var in "${existing_env_vars[@]}"; do
|
2026-01-30 10:36:49 +05:30
|
|
|
env_var_name="${env_var%%=*}"
|
|
|
|
|
env_var_value=${!env_var_name:-}
|
2026-01-14 19:55:03 +05:30
|
|
|
|
2026-01-30 10:36:49 +05:30
|
|
|
# Skip current iteration if the environment variable's value
|
|
|
|
|
# in the current envionment is unset.
|
|
|
|
|
if [[ -z "${env_var_value}" ]]; then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
env_var_val_str_to_compare="${env_var_name}=${env_var_value}"
|
|
|
|
|
env_var_val_str_to_compare_ansi_c_quoted="${env_var_name}=\$'$(printf '%q' "${env_var_value}")'"
|
|
|
|
|
if [[ "${env_var}" == "${env_var_val_str_to_compare}" ]]; then
|
|
|
|
|
continue
|
|
|
|
|
elif [[ "${env_var}" == "${env_var_val_str_to_compare_ansi_c_quoted}" ]]; then
|
|
|
|
|
continue
|
2026-01-14 19:55:03 +05:30
|
|
|
fi
|
2026-01-30 10:36:49 +05:30
|
|
|
systemctl --user import-environment "${env_var_name}" ||:
|
2026-01-14 19:55:03 +05:30
|
|
|
done
|
2026-01-06 06:26:44 +05:30
|
|
|
fi
|
|
|
|
|
|
2025-08-29 16:44:53 +02:00
|
|
|
# Run cosmic-session
|
|
|
|
|
if [[ -z "${DBUS_SESSION_BUS_ADDRESS}" ]]; then
|
|
|
|
|
exec /usr/bin/dbus-run-session -- /usr/bin/cosmic-session
|
|
|
|
|
else
|
|
|
|
|
exec /usr/bin/cosmic-session
|
|
|
|
|
fi
|