I should probably first check if the current display variable is valid and use that.
For example if the current display variable of the host is:
Code: Select all
puppypc1365/unix:10
Code: Select all
export DISPLAY=:10
Code: Select all
puppypc1365:10
I think that if we add an entry starting with "127.0.0.1:10" to the ,Xauthority file by using the xhost (or xauth?) command then we can use TCP sockets instead of unix sockets. Well we can provided the ssh server uses the option "X11UseLocalhost no"
Anyway, here is the script:
Code: Select all
function get_display(){
if [ "$BIND_X11_SOCKETS" = yes ]; then
xauth list | grep "$(hostname)" | grep unix | \
while read line; do
export DISPLAY=:"$(echo "$line" | sed 's/^.*[:]\([0-9.]*\)\([[:space:]]\).*/\1/g')"
if [ xset q &>/dev/null ]; then #The display is valid
break
fi
done
echo "$DISPLAY"
else #else branch not tested
xauth list | grep "$(hostname)" | grep -v unix | \
while read line; do
export DISPLAY=:"$(echo "$line" | sed 's%^.*[/]\([0-9.]*\)\([[:space:]]\).*%\1%g')"
if [ xset q &>/dev/null ]; then #The display is valid
break
fi
done
echo "$DISPLAY"
fi
}
...
if [ "$BIND_X11_SOCKETS" = yes ]; then
SB=/mnt/sb/fakeroot
mkdir -p $SB/tmp/.X11-unix
mount --bind /tmp/.X11-unix $SB/tmp/.X11-unix
cp /root/.Xauthority $FAKEROOT/root/.Xauthority
fi
export DISPLAY="$(get_display)"
This script is a modified version of the one in my psandbox project.