Tuesday, May 13, 2008

Fully functioning Automation Script for Linux multiseat / multiterminal


Introduction:
All you have to do is to put this script in your computer and set it to execute before gdm starts when starting the computer
It will automatically detect the hardware configuration and make the changes at the startup time
So you can plug as many as VGAs and MOUSEs KBDs to the computer and restart the computer. The script will automatically reconfigure the system according to current configuration
In the same way if your remove the hardware, the script will reconfigure the system to current hardware configuration
Detected hardware and some parameters are available in /etc/multiseat.conf
If the script did not detect the driver for vga correctly it will use VESA as the driver. If you know the driver so you can edit /etc/multiseat.conf to fit the configuration. When you are making configuration manually make reconfigure=false in /etc/multiseat.conf to not to overwrite at next startup. You can also edit the script to insert correct driver at startup time also. The script is not that difficult to understand.
If you want to do the configuration in verbose mode you can make verbose=true in /etc/multiseat.conf
If you do not want to reconfigure the system every time, the system boot make reconfigure=false in /etc/multiseat.conf

Ref:
Chris Tyler's Blog
Installation:

  1. Copy the script given bellow to a file eg: MXconfGen
    1. cat > MXconfGen
    2. Past the coppyed content
    3. press CTRL+C
  2. Make the script executable
    1. chmod +x MXconfGen
  3. Place the script in /etc/init.d/
    1. sudo cp MXconfGen /etc/init.d/
  4. Make it execute at start time
    1. sudo update-rc.d MXconfGen start 70 S .
    2. this command works for debian based systems
  5. Now reboot the system THATS ALL!

Find more info in our WASN website at University
There go to Research > Linux Multiseat environment



#!/bin/bash

# Copyright (C) 2008 Nayanajit Mahendra Laxaman WASN-LAB University of Colombo School of Computing mail: nmlaxaman@gmail.com

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

conf="/etc/multiseat.conf"

source $conf
if [ $reconfigure == false ]
then
echo -e '\033[00;32m**NOT\033[00;00mConfiguring /etc/multiseat.conf no /etc/gdm/gdm.conf-custom'
#echo "Set reconfigure=true in /etc/multiseat.confif you want to reconfigure /etc/multiseat.conf no /etc/gdm/gdm.conf-custom in netx boot"
else
echo -e '\033[00;32m**\033[00;00mConfiguring /etc/multiseat.conf...'
##############################INPUT DEVICES################################




: ${DIALOG=whiptail}

: ${DIALOG_OK=0}
: ${DIALOG_CANCEL=1}
: ${DIALOG_ESC=255}
: ${DIALOG_RENAME=3}

tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15

echo "#Multiseat device configuration file auto generated by multiseat_config on `date +'%Y-%m-%d.%H:%M:%S'` " > $conf
echo "reconfigure=true" >> $conf
echo "vbrose=false" >> $conf




for inputdev in mouse kbd;
do
list=""
s="s"
if [ $vbrose == true ] ; then
count=0
for item in `cat /proc/bus/input/devices | grep -i $inputdev -B3 | grep Phys | grep -e isa -e usb | awk '{print $2}' | grep input0 | sed -e s/Phys=// -e s@isa[0-9].../input[0-9]@@` ;
do
list="$list $item $inputdev:$count on";
count=$( expr $count + 1 )
done
$DIALOG --backtitle "$inputdev$s configuration" \
--title "$inputdev list" \
--checklist "Avilable $inputdev s are listed bellow with physical address please select the correct ones. /prc/bus/input/devices will be helpful when choosing the correct devices " 20 45 5 \
$list 2> $tempfile

retval=$?
choice=`cat $tempfile`
case $retval in
$DIALOG_OK)
choices=$( echo $choices | sed s/'"'// );
echo "$inputdev$s=\"$choice\"" >> $conf ;;
$DIALOG_CANCEL)
echo "Cancel pressed.";;
$DIALOG_ESC)
echo "ESC pressed.";;
*)
echo "Unexpected return code: $retval (ok would be $DIALOG_OK)";;
esac
else
list=$( cat /proc/bus/input/devices | grep -i $inputdev -B3 | grep Phys | grep -e isa -e usb | awk '{print $2}' | grep input0 | sed -e s/Phys=// -e s@isa[0-9].../input[0-9]@@ )
list=$( echo $list )
echo "$inputdev$s=\"$list\"" >> $conf
fi
done





####################################VGA#####################################
function hextodec(){
let i1=$( echo $1 | awk -F ':' '{print "0x"$1}' )
i2=$( echo $1 | awk -F ':' '{print $2}' )
let i3=$( echo $i2 | awk -F '.' '{print "0x"$1}' )
let i4=$( echo $i2 | awk -F '.' '{print "0x"$2}' )
echo "$i1:$i3:$i4"
}

devices=""
vgas=$( lspci | grep VGA | awk '{print $5"@"$1}' )
for vga in $vgas
do
driver=`echo $vga | awk -F '@' '{print $1}'`
busid=`echo $vga | awk -F '@' '{print $2}'`
case $driver in
Intel)
driver="intel"
;;
ATI)
driver="ati"
;;
Matrox)
driver="mga"
;;
nVidia)
driver="nv"
;;
Silicon)
driver="sis"
;;
*)
driver="vesa"
echo "**Default driver choosen for VGA if you aware with the driver name, please modify $driver@PCI:$busid in $conf "
;;
esac
busid=$( hextodec $busid )
devices="$devices $driver@PCI:$busid"
done

if [ $vbrose == true ] ; then
$DIALOG --backtitle "VGA configuration" --inputbox "Auto generated devices string is given bellow with the format @PCI: you can change now if you will" 10 60 "$devices" 2> $tempfile

retval=$?
choice=`cat $tempfile`
case $retval in
$DIALOG_OK)
echo "devices=\"$choice\"" >> $conf;;
$DIALOG_CANCEL)
echo "Cancel pressed.";;
$DIALOG_ESC)
echo "ESC pressed.";;
*)
echo "Unexpected return code: $retval (ok would be $DIALOG_OK)";;
esac

else
echo "devices=\"$devices\"" >> $conf
fi





#############################writing gdm.conf-custom#############################
source $conf

stdserverid=':N:=Standard:N:
'
stdserver='
[server-Standard:N:]
name=Standard server
command=/usr/X11R6/bin/X -novtswitch -sharevts -layout layout:N:
flexible=false
'
sing=0

for device in $devices
do
sing=$( expr $sing + 1 )
done

dno=0
if [[ $sing -gt 1 ]]
then
for device in $devices
do
serverid="$serverid
$( echo "$stdserverid" |sed s/:N:/$dno/ |sed s/:N:/$dno/)"
server="$server"$(echo "$stdserver" |sed s/:N:/$dno/ |sed s/:N:/$dno/);
dno=$( expr $dno + 1 )
done

gdmconf="/etc/gdm/gdm.conf-custom"

echo -e '\033[00;32m**\033[00;00mConfiguring /etc/gdm/gdm.conf-custom...'
#cp $gdmconf $gdmconf.`date +'%Y-%m-%d.%H-%M-%S'`
if [[ ! -f "$gdmconf.bak" ]]
then
cp "$gdmconf" "$gdmconf.bak"
fi
echo "#Multiseat gdm configuration file auto generated by multiseat_config on `date +'%Y-%m-%d.%H:%M:%S'`" > $gdmconf
echo "[servers]" >> $gdmconf
echo "$serverid" >> $gdmconf
echo "$server" >> $gdmconf
else
echo -e '\033[00;32m**\033[00;00mFound single VGA card computer!!'

#restoring gdm.conf-custom
gdmconf="/etc/gdm/gdm.conf-custom"
xconf="/etc/X11/xorg.conf"

if [[ -f "$gdmconf.bak" ]]
then
cp "$gdmconf.bak" "$gdmconf"
else
rm -f "$gdmconf"
fi

#Restoring xorg.conf
if [[ -f $xconf.bak ]]
then
cp $xconf.bak $xconf
else
dpkg-reconfigure -phigh xserver-xorg
fi

exit 0
fi
fi




###########################setting up startup script##########################

conf=/etc/multiseat.conf

source $conf

mousesection='
Section "InputDevice"
Identifier "mouse:M:"
Driver "mouse"
Option "Device" "/dev/input/:E:"
Option "CorePointer"
Option "ZAxisMapping" "4 5"
Option "Emulate3Buttons" "true"
EndSection
'
kbdsection='
Section "InputDevice"
Identifier "keyboard:K:"
Driver "evdev"
Option "Device" "/dev/input/:E:"
Option "CoreKeyboard"
Option "XkbRules" "xorg"
Option "XkbModel" "evdev"
Option "XkbLayout" "us"
EndSection
'
devsection='
Section "Device"
Identifier "device:D:"
Driver ":DR:"
Busid ":B:"
EndSection
'
monitorsection='
Section "Monitor"
Identifier "monitor:MO:"
Option "DPMS"
EndSection
'
screensection='
Section "Screen"
Identifier "screen:S:"
Device "device:D:"
Monitor "monitor:MO:"
Defaultdepth 24
SubSection "Display"
Modes "1024x768"
EndSubSection
EndSection
'
layoutsection='
Section "ServerLayout"
Identifier "layout:L:"
screen "screen:S:"
Inputdevice "keyboard:K:"
Inputdevice "mouse:M:"
Option "IsolateDevice" ":B:"
EndSection
'
initlayoutsection='
Section "ServerLayout"
Identifier "layout:L:"
screen "screen:S:"
Inputdevice "keyboard:K:"
Inputdevice "mouse:M:"
Option "IsolateDevice" ":B:"
EndSection
'


flagssection='
Section "ServerFlags"
# Option "DontZap" "true"
# Option "DontVTSwitch" "true"
# Option "HandleSpecialKeys" "Always"
# Option "BlankTime" "0"
# Option "StandbyTime" "0"
# Option "SuspendTime" "0"
# Option "OffTime" "0"
Option "AllowMouseOpenFail" "true"
EndSection
'

mouse=""
kbd=""
mno=0
kno=0
dno=0

xconf=/etc/X11/xorg.conf

echo -e '\033[00;32m**\033[00;00mConfiguring /etc/X11/xorg.conf...'
#cp $xconf $xconf.`date +'%Y-%m-%d.%H-%M-%S'`
if [ ! -f $xconf.bak ]
then
cp $xconf $xconf.bak
fi

echo "#Generated by MXconfGen on `date`" > $xconf

for mouse in $mouses
do
dev=`grep -A3 $mouse /proc/bus/input/devices | grep 'H: Handlers=' | grep --only-matching -e 'mouse[0-9]*'`
echo "$mousesection" | sed -e s/:E:/$dev/ -e s/:M:/$mno/ >> $xconf
mno=$( expr $mno + 1 )
done

for kbd in $kbds
do
dev=`grep -A3 $kbd /proc/bus/input/devices | grep 'H: Handlers=' | grep --only-matching -e 'event[0-9]*'`
echo "$kbdsection" | sed -e s/:E:/$dev/ -e s/:K:/$kno/ >> $xconf
kno=$( expr $kno + 1 )
done

for device in $devices
do
driver=$( echo $device | awk -F '@' '{print $1}' )
busid=$( echo $device | awk -F '@' '{print $2}' )
echo "$devsection" | sed -e s/:DR:/$driver/ -e s/:B:/$busid/ -e s/:D:/$dno/ >> $xconf
echo "$monitorsection" | sed s/:MO:/$dno/ >> $xconf
echo "$screensection" | sed -e s/:S:/$dno/ -e s/:D:/$dno/ -e s/:MO:/$dno/ >> $xconf
echo "$layoutsection" | sed -e s/:L:/$dno/ -e s/:L:/$dno/ -e s/:K:/$dno/ -e s/:M:/$dno/ -e s/:B:/$busid/ -e s/:S:/$dno/ >> $xconf
dno=$( expr $dno + 1 )
done

echo "$flagssection" >> $xconf



8 comments:

  1. Hi thanks for the script and remastered ubuntu iso.I will download and test and get back to you with details on how it will function/work.One question is, will it function/work with dual head ATI/Nvidia VGA cards..?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Is there a way one can use your automating script on other LINUX distros, eg fedora,suse,mandriva,centos,redhat etc.

    ReplyDelete
  4. This script only work for multiple VGA cards not for dual head cards. It is working with ATI/Nvidia cards. The script should work for all Linux distros which uses gdm as desktop manager.

    We are working on improve the script to support dual head VGA cards soon

    ReplyDelete
  5. Thanks for the quick responses.Does it mean ubuntu-8.04-desktop-custom.iso will not work with dual-head cards too?

    ReplyDelete
  6. ubuntu-8.04-desktop-custom.iso also contain the same script so it will also not work for dual head VGAs. Very soon it will be working...

    ReplyDelete
  7. I have download ubuntu-8.04-desktop-custom-2.iso and install in my computer. How to activated the multiterminal computer ? I can see Ubuntu start successly in one monitor but the other monitor blank. I have attached 1 PCI VGA, 1 USB Mouse, 1 USB Keyboard, 1 Serial Mouse and 1 Serial Keyboard. Ubuntu start succesly in monitor which onboard VGA. Thank you.

    ReplyDelete
  8. Most computers can not use both on-board VGA and separate VGAs. So you may require to plug two separate VGAs. At the same time enable separate VGAs in BIOS.

    ReplyDelete