diff options
author | Yuchen Pei <id@ypei.org> | 2024-05-26 15:11:45 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2024-05-26 15:11:45 +1000 |
commit | b968741db7c1cdc6e3d4489f0991c0c51278aad9 (patch) | |
tree | 298e235b12f65fb81cf9942f55dd11b1b8cf8d00 | |
parent | 8976fd48fce00cb627e61e93680a5f891df5f8fd (diff) |
[bash] ensure xdg_runtime_dir
https://unix.stackexchange.com/questions/476963/how-to-create-delete-xdg-runtime-dir-at-login-logoff
-rw-r--r-- | misc/.bashrc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/misc/.bashrc b/misc/.bashrc index 115dab5..95079eb 100644 --- a/misc/.bashrc +++ b/misc/.bashrc @@ -208,6 +208,26 @@ export QT_IM_MODULE=ibus #fix small vlc interface export QT_AUTO_SCREEN_SCALE_FACTOR=0 +# ensure $XDG_RUNTIME_DIR is set +if [ -z "$XDG_RUNTIME_DIR" ]; then # It's not already set + XDG_RUNTIME_DIR=/run/user/$UID # Try systemd created path + if [ ! -d "$XDG_RUNTIME_DIR" ]; then + # systemd-created directory doesn't exist + XDG_RUNTIME_DIR=/tmp/$USER-runtime + if [ ! -d "$XDG_RUNTIME_DIR" ]; then # Doesn't already exist + mkdir -m 0700 "$XDG_RUNTIME_DIR" + fi + fi +fi +# Check dir has got the correct type, ownership, and permissions +if ! [[ -d "$XDG_RUNTIME_DIR" && -O "$XDG_RUNTIME_DIR" && + "$(stat -c '%a' "$XDG_RUNTIME_DIR")" = 700 ]]; then + echo "\$XDG_RUNTIME_DIR: permissions problem with $XDG_RUNTIME_DIR:" >&2 + ls -ld "$XDG_RUNTIME_DIR" >&2 + XDG_RUNTIME_DIR=$(mktemp -d /tmp/"$USER"-runtime-XXXXXX) + echo "Set \$XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" >&2 +fi + # start the agent automatically and make sure that only one # ssh-agent process runs at a time if ! pgrep -u "$USER" ssh-agent > /dev/null; then |