orangesquid (os) wrote,
orangesquid
os

the joys of x2x

I now have x2x extending the desktop on anisotropy to sheripc (key+mouse now off of the desk, saving space!). It's really neat. x2x compiled cleanly with xmkmf -a && make. I have a few helper scripts...
anisotropy:/home/os/.x2x-autostart:
(requires tweaking if other machine's $USER should match something other than current one's and/or $DISPLAY is not :0 on target; also, modify 'sheripc' to be the hostname of target X display)
#!/bin/bash
x2xopts="-wait -west"
if ping -w10 -c2 sheripc 2>/dev/null | fgrep -q ' bytes from '
then
  echo sheripc is up at `date`
  ps=$(ssh sheripc '/sbin/pidof xinit && ps -flwww `/sbin/pidof xinit`')
  if [ -n "$ps" ]; then
    xuser=$(tail +3 <<<"$ps" | awk '{print $3}')
    echo xinit running as pid $(head -n1 <<< "$ps") and user "$xuser"
    if [ "$xuser" = "$USER" ]; then
      echo xinit user "$xuser" matches local user "$USER"
      if [ "$1" != "-noxauth" ]; then
        auth=$(
          ssh sheripc \
            '/usr/X11/bin/xauth list |
              grep "^$(
                      hostname -f |
                        sed "s/\\./\\\\./g"
                    ):" |
              head -n1'
        )
        disp=$(awk '{print $1}' <<< "$auth")
        echo xauth string for "$disp" is: "$auth"
        /usr/X11/bin/xauth add $auth
      fi
      if [ "$1" != "-xauthonly" ]; then
        echo invoking x2x with these options: "( $x2xopts )"
        x2x -to "$disp" $x2xopts &
        echo interrupting dpms state
        ssh sheripc "/usr/X11/bin/xset -display :0 dpms force on"
      fi
    fi
  fi
fi


anisotropy:/home/os/.x2x-helpers-autostart:
(change script names as appropriate:)
#!/bin/bash
sleep 25
if ! pidof x2x >/dev/null ; then
  echo x2x not running
  exit 1
fi
/home/os/xterm-transplant-sheripc &
if /home/os/xauth-sheripc-reverse ; then
  /home/os/xterm-sheripc &
  sleep 5
  xtwin=$(
    xlsclients -l |
      awk '/^Window/{w=$2}!/^Window/{print w,$0}' |
      grep 'display.*ash.*DISPLAY' |
      cut -d: -f1
  )
  if [ -z "$xtwin" ]; then
    echo could not find transplanted xterm win
    exit 1
  fi
  for w in $xtwin ; do
    wmctrl -v -i -r $w -t 3
  done
else
  echo xauth cookie copy failed
  exit 1
fi


anisotropy:/home/os/xauth-sheripc-reverse:
(rename as appropriate, change hostname 'sheripc', and change hardcoded IP of local machine (here, anisotropy) or fetch via ip/ifconfig)
#!/bin/bash
hostregex=$(
  hostname -f |
    sed "s/\\./\\\\./g"
)
hostip=172.24.16.19
echo "using $hostip for /$hostregex/"
auth=$(
  xauth list |
    grep "^$hostregex:" |
    head -n1 |
    sed "s/^$hostregex:/$hostip:/"
)
if [ -z "$auth" ]; then
  echo could not get auth string
  exit 1
fi
echo "got transformed auth str: \"$auth\""
ssh sheripc /usr/X11/bin/xauth add $auth
retval=$?
if [ $retval -eq 0 ]; then
  echo successfully added auth cookie to sheripc
else
  echo could not add auth cookie to sheripc
fi
exit $retval


anisotropy:/home/os/xterm-transplant-sheripc:
(rename as appropriate, change hostname 'sheripc', change out 'ash' for 'bash' if needed, and change $DISPLAY if necessary)
#!/bin/ash
xterm -rv +ls -display sheripc:0 -e \
  ash -c "export DISPLAY=:0.0 ; bash -l"



anisotropy:/home/os/xterm-sheripc:
(rename as appropriate, change hardcoded IP for anisotropy, change hostname 'sheripc', change out 'ash' for 'bash' if needed, and change $DISPLAY if necessary)
#!/bin/ash
ssh -f sheripc \
  xterm -rv +ls -display 172.24.16.19:0 -e \
    ash -c '"export DISPLAY=:0.0 ; bash -l"'


sheripc:/home/os/xterm-anisotropy:
(rename as appropriate, change hardcoded IP for anisotropy, change out 'ash' for 'bash' if needed, and change $DISPLAY if necessary)
#!/bin/ash
ssh -f 172.24.16.19 \
  xterm -rv +ls -display sheripc:0 -e \
    ash -c '"export DISPLAY=:0.0 ; bash -l"'


sheripc:/home/os/xterm-transplant-anisotropy:
(rename as appropriate, change hardcoded IP for anisotropy, change out 'ash' for 'bash' if needed, and change $DISPLAY if necessary)
#!/bin/ash
xterm -rv +ls -display 172.24.16.19:0 -e \
  ash -c "export DISPLAY=:0.0 ; bash -l"


Then, be sure to ssh-keygen -t dsa (or rsa etc) on both machines and append each .ssh/id_dsa.pub (or id_rsa.pub etc) to .ssh/authorized_keys on the opposite box (if it doesn't exist already, chmod it 600), and have your window manager on your 'anisotropy' box invoke /home/'os'/.x2x-{helpers-,}autostart -- for recent xfce, you can use these files, modified with your user directory appropriately:

anisotropy:/home/os/.config/autostart/x2x.desktop
[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=x2x
Comment=x2x remote DISPLAY k/m controller
Exec=/home/os/.x2x-autostart
StartupNotify=false
Terminal=false
Hidden=false


anisotropy:/home/os/.config/autostart/x2x-helpers.desktop
[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=x2x helpers
Comment=x2x helpers (reverse xauth, transplanted xterms)
Exec=/home/os/.x2x-helpers-autostart
StartupNotify=false
Terminal=false
Hidden=false


Be sure to also install wmctrl to shift things to the appropriate workspace (see lines in scripts above; modify as desired).


Tags: wmctrl, x11, x2x
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments