cosmic-session/data/start-cosmic
Christoph Dalski 2770d1155a fix: login shell path interpreted as string by modern shells
The single quotes around the login shell path are interpreted as string by modern shells like nushell.
The exec call breaks.

Tested locally with nushell.

Fixes: #221
2026-09-16 22:02:14 +02:00

110 lines
4.2 KiB
Bash
Executable file

#!/bin/sh
set -e
# From: https://people.debian.org/~mpitt/systemd.conf-2016-graphical-session.pdf
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
done
fi
# 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
# `-l`: start $SHELL as a login shell so it sources the user's profile.
exec "${SHELL}" -l -c "${0} --in-login-shell"
fi
fi
export XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:=COSMIC}"
export XDG_SESSION_DESKTOP="${XDG_SESSION_DESKTOP:=COSMIC}"
export XDG_SESSION_TYPE="${XDG_SESSION_TYPE:=wayland}"
export _JAVA_AWT_WM_NONREPARENTING=1
export GDK_BACKEND=wayland,x11
export MOZ_ENABLE_WAYLAND=1
export QT_QPA_PLATFORM="wayland;xcb"
export QT_AUTO_SCREEN_SCALE_FACTOR=1
export QT_ENABLE_HIGHDPI_SCALING=1
export DCONF_PROFILE=cosmic
# Set the QT platform theme to CuteCosmic. Fallback to qt6ct if CuteCosmic is not installed.
if [ -z "$QT_QPA_PLATFORMTHEME" ]; then
export QT_QPA_PLATFORMTHEME=cosmic
for QT_PLUGIN_PATH in /usr/lib*/qt6/plugins /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
elif [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt6ct.so" ] || [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt5ct.so" ]; then
# Fallback to qt6ct, but keep looking for CuteCosmic.
# Note that "qt5ct" is compatible with both qt5ct and qt6ct.
export QT_QPA_PLATFORMTHEME=qt5ct
fi
done
fi
# Start gnome keyring components if the daemon is active
# -> check if $XDG_RUNTIME_DIR/keyring exists
if [ -d "$XDG_RUNTIME_DIR/keyring" ]; then
# Use PATH lookup instead of hardcoding /usr/bin
if command -v gnome-keyring-daemon >/dev/null 2>&1; then
eval "$(gnome-keyring-daemon --start --components=pkcs11,secrets,ssh > /dev/null 2>&1)"
else
echo "gnome-keyring-daemon not found in PATH" >&2
fi
# 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 "$XDG_RUNTIME_DIR/gcr/ssh" ]; then
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/gcr/ssh"
elif [ -S "$XDG_RUNTIME_DIR/keyring/ssh" ]; then
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/keyring/ssh"
fi
fi
if command -v systemctl >/dev/null; then
# Import some variables that we explicitly want to have available
# in the user session.
systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP DCONF_PROFILE SSH_AUTH_SOCK
# For environment variables already imported into the user's
# session, if the value imported differs from the value in this
# environment, update it.
systemctl --user show-environment | while IFS= read -r env_var; do
env_var_name="${env_var%%=*}"
env_var_value="$(printenv "${env_var_name}" || true)"
# Skip current iteration if the environment variable's value
# in the current envionment is unset.
if [ -z "${env_var_value}" ]; then
continue
fi
# Skip updating variables where systemd already holds this exact value.
if [ "${env_var}" = "${env_var_name}=${env_var_value}" ]; then
continue
fi
systemctl --user import-environment "${env_var_name}" || true
done
fi
# 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