From: Iain Patterson Date: Mon, 20 Jan 2014 16:07:24 +0000 (+0000) Subject: Handle non-default XAUTHORITY. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;ds=inline;h=a0a218b2d904a23bf4cd0f2758cf59b847c24c4f;p=profile.git Handle non-default XAUTHORITY. 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. --- diff --git a/.profile.d/xauth.bashrc b/.profile.d/xauth.bashrc new file mode 100644 index 0000000..0cf088c --- /dev/null +++ b/.profile.d/xauth.bashrc @@ -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