Handle non-default XAUTHORITY.
authorIain Patterson <me@iain.cx>
Mon, 20 Jan 2014 16:07:24 +0000 (16:07 +0000)
committerIain Patterson <me@iain.cx>
Mon, 20 Jan 2014 16:11:16 +0000 (16:11 +0000)
Newer Fedora versions set XAUTHORITY to a file in /tmp.  Not helpful in
an NFS environment.  Not at all helpful when running sudo and finding
the XAUTHORITY file owned by root.

.profile.d/xauth.bashrc [new file with mode: 0644]

diff --git a/.profile.d/xauth.bashrc b/.profile.d/xauth.bashrc
new file mode 100644 (file)
index 0000000..0cf088c
--- /dev/null
@@ -0,0 +1,17 @@
+# Merge xauth cookies into home stash.
+if [ -n "$XAUTHORITY" ]; then
+  if [ -r "$XAUTHORITY" ]; then
+    # If we are root the old file may have been chowned.
+    [ -n "$SUDO_UID" -a -O "$XAUTHORITY" ] && chown "$SUDO_UID" "$XAUTHORITY"
+    [ -n "$SUDO_GID" -a -G "$XAUTHORITY" ] && chgrp "$SUDO_GID" "$XAUTHORITY"
+
+    # Merge and unset.
+    exec 3<&0 < "$XAUTHORITY"
+    unset XAUTHORITY
+    xauth merge - 2>/dev/null
+    exec <&3 3<&-
+  else
+    # We can't read the file so just unset.
+    unset XAUTHORITY
+  fi
+fi