[X2Go-Dev] Two additions to X2Go-TCE

Stefan Baur newsgroups.mail2 at stefanbaur.de
Tue Nov 26 00:47:38 CET 2013


Hi,

as those of you also subscribed to the x2go-user mailing list might 
already have noticed, I'm currently evaluating X2Go-ThinClient-Edition.
This is purely for my own, at-home use, as opposed to the published 
application mode, which I'm using commercially.

One thing that has always annoyed me about X2Go is the mechanism for 
printing to a locally-attached client printer.

Especially in a thinclient, LAN-only setup, it seems like an unnecessary 
complex solution to a trivial problem.

My solution: Make the ThinClients behave like a "HP JetDirect" card.

This can easily be done like this (on the server supplying the TC NFS root):

chroot /opt/x2gothinclient/chroot
apt-get install openbsd-inetd -y
echo "9100 stream tcp nowait root /bin/dd if=- of=/dev/usb/lp0 bs=1024k" 
 >> /etc/inetd.conf
echo "9101 stream tcp nowait root /bin/dd if=- of=/dev/usb/lp1 bs=1024k" 
 >> /etc/inetd.conf

Assumption: Thinclients will have no more than two locally attached 
printers. For more, simply keep adding lines and increment the port 
numbers by 1 (9102: /dev/usb/lpt2, 9103: /dev/usb/lpt3, etc).

For more flexibility, this could also be created dynamically at boot, by 
turning inetd.conf into a symlink to a writable file on a ramdisk, and a 
script checking for the presence of /dev/usb/lp* and /dev/lp* (in case 
somebody uses an ancient computer with a parallel printer as thinclient).

With this addition (either statically as shown above, or with the use of 
a script), all you need to do on the CUPS server is set up a printer and 
specify socket://name-or-ip-of-the-thinclient:portnumber, e.g. 
socket://thinclient01.example.com:9100, as AppSocket/HP JetDirect URI in 
CUPS.

Now, this will end up in a mess if you're assigning IPs dynamically via 
DHCP, and you aren't matching them up with the thinclients' MAC addresses.

The easy solution for that would be using a DNS name, however, right 
now, it looks like all X2Go thin clients don't request/suggest a DNS 
name via DHCP, and use the same name "x2gothinclient" locally. Seems 
like "send host-name = gethostname();" in  /etc/dhcp/dhclient.conf 
somehow doesn't work properly in the thin client environment - possibly 
because PXE already pulls a DHCP IP and doesn't know about the name? I'm 
not sure what the mechanism there does.

Therefore, I would like to suggest the addition of some code that adds 
an individual name to each client, and requests/suggests that via DHCP.
The MAC address would come in handy for that.
A method to query the MAC address of the currently active interface 
would be:

IFACE=$(route -n | awk '/^0.0.0.0/ { print $8 }' | head -1)
MAC=$( ip a l $IFACE | awk '/^ *link/ { print $2 }' | tr ':' '-' )
hostname "$(cat /etc/hostname)-$MAC" # this sets the hostname
dhclient -sf /dev/null $IFACE # this re-registers our lease and updates 
the name on the DHCP/DNS server, without complaining about a read-only 
resolv.conf-file
# NB: Yes, you really need to use /dev/null, not /dev/zero.

Notes:
1) This is a quick hack, feel free to improve it
2) I'm not sure where this should be inserted, only that it should be 
inserted. ;-) Right now, I'm running it in rc.local, but there must be a 
better place for this. The earlier in the boot process, the better. 
Maybe as a script in /etc/network/if-up.d/ ?
3) I don't know if changing the host name without changing /etc/hostname 
and /etc/hosts might have some undesired side effects. If it does, these 
files might have to be symlinked to a ramdisk.

-Stefan



More information about the x2go-dev mailing list