Thursday, June 19, 2008

Modification for fully functioning Automation Script for Linux multiseat / multiterminal

This modified script will work for more than 2 terminals
**Installation is similar to earlier script
Ref:Multiterminal with evdev
New version:
#!/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##############################
#command=/usr/X11R6/bin/X -nolisten tcp -novtswitch -sharevts -layout layout:N: vt:T: ::N:
source $conf

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

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

dno=0
tno=2
if [[ $sing -gt 1 ]]
then
for device in $devices
do
ln -s $( which X ) $( which X )$dno 2>/dev/null

serverid="$serverid
$( echo "$stdserverid" |sed s/:N:/$dno/ |sed s/:N:/$dno/)"
server="$server"$(echo "$stdserver" |sed -e s/:N:/$dno/ -e s/:N:/$dno/ -e s/:N:/$dno/ -e s/:T:/$tno/);
dno=$( expr $dno + 1 )
tno=$( expr $tno + 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:"
Option "NoInt10" "Yes"
EndSection
'
devsection_p='
Section "Device"
Identifier "device:D:"
Driver ":DR:"
Busid ":B:"
Option "NoInt10" "No"
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 "1360x768" "1280x1024" "1024x768"
EndSubSection
EndSection
'
layoutsection='
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
pxconf=/etc/X11/xorg.conf.probe

echo -e '\033[00;32m**\033[00;00mConfiguring /etc/X11/xorg.conf and /etc/X11/xorg.conf.probe ...'
#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
echo "#Generated by MXconfGen on `date` for probe only" > $pxconf

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

###################Creating xorg.conf.probe for Xorg probing####################


echo "$devsection_p" | sed -e s/:DR:/$driver/ -e s/:B:/$busid/ -e s/:D:/$dno/ >> $pxconf
echo "$monitorsection" | sed s/:MO:/$dno/ >> $pxconf
echo "$screensection" | sed -e s/:S:/$dno/ -e s/:D:/$dno/ -e s/:MO:/$dno/ >> $pxconf

dno=$( expr $dno + 1 )
done

screens=""
sno=0

for device in $devices
do
screens=$screens" screen \"screen$sno\"
"
sno=$( expr $sno + 1 )
done


echo '
Section "ServerLayout"
Identifier "probe"' >> $pxconf
echo "$screens" >> $pxconf
echo 'EndSection' >> $pxconf

############################ server flags for xorg.conf#####################
echo "$flagssection" >> $xconf

#################################probing Xorg###############################
echo -e '\033[00;32m**\033[00;00mProbing Xorg ...'
Xorg -config $pxconf -probeonly 2>/dev/null

6 comments:

  1. No wonder i tried setting up a 4-seater system and it didnt work only two seats worked.Thanks for the new script,i will try and get back to you, will this script work with dual-headed cards now.?

    ReplyDelete
  2. It still not working for multi head video cards only for single head.

    ReplyDelete
  3. Hi,how far is the release of script to automate multiseat in dual-headed vga cards environment?
    Thanks in advance and continue the good work you are doing!

    ReplyDelete
  4. Hi laxaman, great job.
    If the script for dual-headed cards is ready, i would test it.
    Please publish it here.

    ReplyDelete
  5. hi laxaman, i really appreciate the good work you are doing.kindly if the script for dual head cards is ready publish it,am willing to give it a "test run".
    thanks.

    ReplyDelete
  6. Hi Laxaman, kindly publish the script for dual head graphic cards, I will test and let you know how it goes.

    Regards.

    ReplyDelete