jeudi 5 mars 2015

Check if there is no GUI


Is it possible to check if a UNIX machine (Mac / Linux) has a GUI...


Basically I would like to distinguish between:



  • UNIXes with GUI (i.e. normal Macs, Linuxs)

  • UNIXes with no GUI (i.e. Mac server/ linux server etc.)...


I have tried to use the $DISPLAY variable, but I don't think it works in Mac OS (It doesn't on my Yosemite installation)...




Background


I am writing a (ruby) script that starts up a local server on the UNIX machine and then opens this local server in the default browser (using open http://localhost:4567 or xdg-open http://localhost:4567 depending on the OS)...


The problem is that this script is likely to be used on servers as well as on normal computers (i.e. machines with and without a GUI) and I don't want to annoy users on servers by opening the local server URL in a command line browser (such as lynx etc.)...


NB. I plan to check the $SSH_CLIENT variable (etc.) before I test for the GUI. Thus, the script will not try to open the default browser if you SSH into a machine. So the above is to target users that physically connect to a server (and not through SSH)...


Any HELP would be appreciated... I have looked around on google, but could't find anything that works...



Aucun commentaire:

Enregistrer un commentaire