Skip to content
Snippets Groups Projects
Commit f2bed667 authored by Stephanie Briere Americo's avatar Stephanie Briere Americo
Browse files

Trabalhando na solução com hubs

parent 46c613a1
No related branches found
No related tags found
1 merge request!3SCRUM#337: Detects which hub the device belongs to
#!/bin/bash
# Copyright (C) 2004-2007 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# This script discover evdev mice and keyboards and also discovers video cards
# on the machine.
# For input devices, it uses /proc/bus/input/devices
# For video cardes, it uses the "discover" package.
# TODO: find a decent way to do all this.
DISCOVER=/sbin/discover
# This function prints the physical addresses of the mice found
function discover_input () {
KEYBOARDS=($(hal-find-by-capability --capability input.keyboard))
MICE=($(hal-find-by-capability --capability input.mouse))
for i in ${KEYBOARDS[@]}; do
EVDEV_NODE=$(hal-device $i | grep linux.device_file | cut -d"'" -f2)
echo -e "kbd\t${i}"
echo -e "kevdev\t${EVDEV_NODE}"
done
for i in ${MICE[@]}; do
EVDEV_NODE=$(hal-device $i | grep linux.device_file | cut -d"'" -f2)
echo -e "mouse\t${i}"
echo -e "mevdev\t${EVDEV_NODE}"
done
}
# Prints bus address and drivers of the video cards.
function video_cards () {
# calling discover is way toooooo slow!
OUTPUT=$($DISCOVER -t display --vendor-id --model-id)
VENDOR_IDS=($(echo "$OUTPUT" | cut -d' ' -f1))
MODEL_IDS=($( echo "$OUTPUT" | cut -d' ' -f2))
# There can be empty lines on "drivers"
DRIVERS=($($DISCOVER -t display --data-path=xfree86/server/device/driver \
| sed 's/^$/vesa/g'))
for (( i = 0; i < ${#VENDOR_IDS[@]}; i++)); do
# If there are multiple cards with the same IDs, lspci will print
# multiple lines
# See how many times we already used these IDs:
TIMES_USED=0
for (( j=0; j < i; j++)); do
if ( [ "${VENDOR_IDS[j]}" = "${VENDOR_IDS[i]}" ] &&
[ "${MODEL_IDS[j]}" = "${MODEL_IDS[i]}" ] ); then
TIMES_USED=$((TIMES_USED+1))
fi
done
BUS_IDS[i]=$(lspci -d ${VENDOR_IDS[i]}:${MODEL_IDS[i]} |
cut -d' ' -f1 | head -n $((TIMES_USED+1)) | tail -n 1)
done
for (( i=0 ; i < ${#BUS_IDS[@]}; i++ )) ; do
# busid from lspci is in format 00:00.00
# below we convert 0:00.00 in 00:00:00 and then split in 00, 00 and 00
NUMS=(`echo ${BUS_IDS[$i]} | sed -e "s/\./\:/g" | \
awk 'BEGIN {FS=":"}{print toupper($1), toupper($2), toupper($3)}'`)
# now, we convert the numbers from hexa to decimal base
for (( j=0; j<${#NUMS[@]}; j++ )); do
NUMS[$j]=$(printf "%d" 0x${NUMS[$j]})
done
# putting it all back together
BUS_ID="${NUMS[0]}:${NUMS[1]}:${NUMS[2]}"
echo -e "bus\t${BUS_ID}"
done
for i in ${DRIVERS[@]}; do
echo -e "driver\t$i"
done
} # video_cards
# ******************** MAIN *************************
if [[ "$#" = 0 ]]
then
ARG=all
else
ARG=$1
fi
case $ARG in
all)
CARDS=`video_cards`
INPUT=`discover_input`
echo "$INPUT" | grep mouse
echo "$INPUT" | grep mevdev
echo "$INPUT" | grep kbd
echo "$INPUT" | grep kevdev
echo "$CARDS"
;;
all2)
CARDS=`video_cards`
INPUT=`discover_input`
echo "$INPUT"
echo "$CARDS"
;;
mouse|mevdev|kbd|kevdev)
INPUT=`discover_input`
echo "$INPUT" | grep $ARG
;;
bus|driver)
CARDS=`video_cards`
echo "$CARDS" | grep $ARG
;;
cards)
CARDS=`video_cards`
echo "$CARDS"
;;
#debug)
# echo "$INPUT" | egrep "(PHYS|HANDLER|NAME|--)"
# ;;
*)
echo "$1: unrecognized argument"
echo "Valid parameters: "
echo "mouse: prints the hal ids of the mice"
echo "mevdev: prints the evdev mouse events"
echo "kbd: prints the hal ids of the keyboards"
echo "kevdev: prints the evdev keyboard events"
echo "driver: prints the video card drivers"
echo "cards: prints the video card bus IDs"
echo "all: prints everything"
;;
esac
#!/bin/bash
## Script/function constants
READ_DEVICES=read-devices
WRITE_W=write_window
DEVICES=devices
declare -a SEATS_LISTED # save the name of the existing seats
find_keyboard () {
fKey=$1
wNum=$(($fKey-1))
ONBOARD=$2
SEATS_LISTED=(seat0 $(loginctl list-seats | grep seat-))
CREATED=0
while (( ! CREATED )); do
KEYBOARDS=$(discover-devices kevdev | cut -f2)
for i in `ls $MDM_DEVICES | grep "\<keyboard"`; do
KEYBOARDS=$(sed "s#$i##g" <<< $KEYBOARDS)
done
if [ -z "$KEYBOARDS" ]; then
echo "No keyboards connected"
sleep 1
continue
fi
# See if someone presses the key:
PRESSED=$($READ_DEVICES $fKey $KEYBOARDS | grep '^detect' | cut -d'|' -f2)
if [ -z "$PRESSED" ]; then # if $READ_DEVICES gets killed the script won't do bad stuff
continue
fi
if [ "$PRESSED" = 'timeout' ]; then
continue
fi
CREATED=1
ln -sf $PRESSED $DEVICES/keyboard_$SEAT_NAME
for i in `ls $DEVICES | grep "\<keyboard"`; do
if [ "$i" != "keyboard_$SEAT_NAME" ]; then
AUX=$(stat -c %N $DEVICES/$i | cut -d '>' -f2 | cut -d "'" -f2)
if [ "$AUX" = "$PRESSED" ]; then
# Keyboard link already exists...
rm -f $DEVICES/keyboard_$SEAT_NAME
CREATED=0
fi
fi
done
done
SYS_DEV=/sys$(udevadm info $PRESSED | grep 'P:' | cut -d ' ' -f2- | sed -r 's/event.*$//g')
if [ -n "$SYS_DEV" ]; then
# Now we know the seat/output
SEAT_NAME=${SEATS_LISTED[$wNum]}
loginctl attach $SEAT_NAME $SYS_DEV
find_mouse $fKey $SEAT_NAME
exit 1
else
echo "CAN NOT FIND KEYBOARD"
exit 0
fi
}
find_mouse () {
fKey=$1
SEAT_NAME=$2
CREATED=0
TIMEOUT=0
while (( ! CREATED && ! TIMEOUT )); do
MICE=$($DISCOVER_DEVICES mevdev | cut -f2)
for i in `ls $MDM_DEVICES | grep "\<mouse"`; do
MICE=$(sed "s#$i##g" <<< $MICE)
done
if [ -z "$MICE" ]; then
echo "No mice connected"
sleep 1
continue
fi
# Create the lock
LOCK_EXISTS=1
$WRITE_W wait_load $wNum
while (( LOCK_EXISTS )); do
# creates lock to prevent someone from creating while checking
touch ${MC3SL_DEVICES}/lock${fKey}
LOCK_EXISTS=0
# check if another lock exists
for i in `ls $MC3SL_DEVICES | grep "\<lock"`; do
if [ "$i" != "lock${fKey}" ]; then
LOCK_EXISTS=1
fi
done
# if another lock exists, wait until it is not removed
if (( LOCK_EXISTS )); then
rm -f ${MC3SL_DEVICES}/lock${fKey}
sleep 1;
fi
done
# Now we have the lock!
$WRITE_W press_mouse $wNum
# See if someone presses the button:
PRESSED=$($READ_DEVICES 13 $MICE | grep '^detect' | cut -d'|' -f2)
if [ -z "$PRESSED" ]; then # if $READ_DEVICES gets killed the script won't do bad stuff
rm -f ${MC3SL_DEVICES}/lock${fKey}
continue
fi
if [ "$PRESSED" = 'timeout' ]; then
# Give other machines the opportunity to enter the lock
rm -f ${MC3SL_DEVICES}/lock${fKey}
TIMEOUT=1
continue
fi
CREATED=1
ln -sf $PRESSED $DEVICES/mouse_$SEAT_NAME
for i in `ls $DEVICES | grep "\<mouse"`; do
if [ "$i" != "mouse_$SEAT_NAME" ]; then
AUX=$(stat -c %N $DEVICES/$i | cut -d '>' -f2 | cut -d "'" -f2)
if [ "$AUX" = "$PRESSED" ]; then
# Mouse link already exists...
rm -f $DEVICES/mouse_$SEAT_NAME
CREATED=0
fi
fi
done
rm -f ${MC3SL_DEVICES}/lock${fKey}
done
SYS_DEV=/sys$(udevadm info $PRESSED | grep 'P:' | cut -d ' ' -f2- | sed -r 's/event.*$//g')
if [[ "$CREATED" -eq 1 && -n "$SYS_DEV" ]]; then
loginctl attach $SEAT_NAME $SYS_DEV
$WRITE_W ok $wNum
exit 1
else
$WRITE_W press_key $wNum
rm -f $DEVICES/keyboard_$SEAT_NAME
find_keyboard $fKey $SEAT_NAME
fi
}
#!/bin/bash
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of le-multiterminal
#
# le-multiterminal 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#### Name: multiseat-controller.sh
#### Description: Prepares the environment and launches the seat configuration scripts.
#### Xorg that communicates with the Thinnetworks card (fake-seat) should already be running.
#### Written by: Stephanie Briere Americo - sba16@c3sl.ufpr.br on 2017.
set -x
#TODO: arrumar caminhos
export PATH=$PATH:$(pwd)
## Auxiliary scripts
source find-devices.sh
source window-acess.sh
## Path constants
MC3SL_SCRIPTS=$(pwd) #/usr/sbin/
MC3SL_DEVICES=devices #/etc/mc3sl/devices/
MC3SL_LOGS=$(pwd) #/etc/mc3sl/logs/
## Script/function in other file
DISCOVER_DEVICES="$MC3SL_SCRIPTS/discover-devices"
FIND_KEYBOARD="$MC3SL_SCRIPTS/find_keyboard" # "find-devices.sh"
CREATE_WINDOW="$MC3SL_SCRIPTS/create_window" # "window-acess.sh"
WRITE_WINDOW="$MC3SL_SCRIPTS/write_window" # "window-acess.sh"
## Macros
FAKE_DISPLAY=:90 # display to access fake-seat (secondary card)
OUTPUTS=("LVDS" "VGA") # output options
## Variables
WINDOW_COUNTER=0 # how many windows were created
N_SEATS_LISTED=0 # how many seats are there in the system
ONBOARD=0 # if the onboard is connected
declare -a DISPLAY_XORGS # saves the display of the Xorg processes launched
declare -a ID_WINDOWS # save the created window ids (used in window-acess.sh)
configure_devices () {
# Run configuration script for each seat
for WINDOW in `seq 0 $(($WINDOW_COUNTER-1))`; do
$FIND_KEYBOARD $(($WINDOW+1)) $ONBOARD &
$WRITE_WINDOW press_key $WINDOW
done
}
kill_processes () {
# Cleans the system by killing all the processes it has created
if [[ -n "$(ls | grep lock)" ]]; then
rm lock*
fi
if [[ -n "$(ls $MC3SL_DEVICES)" ]]; then
rm -f $MC3SL_DEVICES/*
fi
pkill -P $$
}
### TODO: Serviços que precisam rodar ANTES desse script
systemctl stop lightdm
Xorg :90 -seat __fake-seat-1__ -dpms -s 0 -nocursor &
sleep 2
### TO-DO end
############ BEGIN ############
# Checks if there is a device connected to the onboard card
if [ "$(cat "/sys$(udevadm info /sys/class/drm/card0 | grep "P:" | cut -d " " -f2)/card0-VGA-1/status")" == "connected" ]; then
# Runs Xorg and creates the window for the onboard card
DISPLAY_XORGS[$WINDOW_COUNTER]=:$(($WINDOW_COUNTER+10))
export DISPLAY=${DISPLAY_XORGS[$WINDOW_COUNTER]}
Xorg ${DISPLAY_XORGS[$WINDOW_COUNTER]} &
sleep 1 # TODO
$CREATE_WINDOW
ONBOARD=1
else
WINDOW_COUNTER=1
fi
# The fake_seat display needs to be exported to run the Xephyr that communicate with it
export DISPLAY=$FAKE_DISPLAY
for i in `seq 0 1`; do
# Display for each output
DISPLAY_XORGS[$WINDOW_COUNTER]=:$((WINDOW_COUNTER+10))
# Run Xephyr to type in this output
Xephyr ${DISPLAY_XORGS[$WINDOW_COUNTER]} -output ${OUTPUTS[$WINDOW_COUNTER]} -noxv &
sleep 2 # TODO
# Export display and create a window to write on this output
export DISPLAY=${DISPLAY_XORGS[$WINDOW_COUNTER]}
$CREATE_WINDOW
# Again: the fake_seat display needs to be exported
export DISPLAY=$FAKE_DISPLAY
done
#loginctl seat-status seat-V0 | grep $(echo "/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2.2/1-1.2.2:1.0/0003:04B3:310C.0008/input/input10" | rev | cut -d "/" -f1 | rev)
configure_devices
# Wait until all seats are configured
N_SEATS_LISTED=$(($(loginctl list-seats | grep -c "seat-")+$ONBOARD))
CONFIGURED_SEATS=0
while [[ $CONFIGURED_SEATS -le $N_SEATS_LISTED ]]; do
wait -n $PID_FIND_DEVICES
CONFIGURED_SEATS=$(($CONFIGURED_SEATS+1))
done
kill_processes
#systemctl start lightdm
exit 0
File added
File added
#!/bin/bash
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of le-multiterminal
#
# le-multiterminal 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#### Description: Given a specific display, these functions create and write in a window.
#### There should already be an Xorg/Xephyr running in this display.
#### Written by: Stephanie Briere Americo - sba16@c3sl.inf.ufpr.br on 2017.
## Script/function in other file
NEW_WINDOW="$MC3SL_SCRIPTS/seat-parent-window" #It receives as parameter <RESOLUTION>x<X_Initial>+<Y_Inicial>
WRITE_MESSAGE="$MC3SL_SCRIPTS/write-message"
create_window () {
#### Description: Create a window in a specific display.
#### ID_WINDOWS and WINDOW_COUNTER are declared in "multiseat-controller.sh".
# Get screen resolution
SCREEN_RESOLUTION=$(xdpyinfo -display ${DISPLAY_XORGS[$WINDOW_COUNTER]} | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
# Creates a new window for writing on this output
WINDOW_NAME=w$(($WINDOW_COUNTER+1))
$NEW_WINDOW $SCREEN_RESOLUTION+0+0 $WINDOW_NAME &
sleep 1 #TODO
# Get the window id
ID_WINDOWS[$WINDOW_COUNTER]=$(xwininfo -name $WINDOW_NAME | grep "Window id" | cut -d ' ' -f4)
# Increases the number of windows
WINDOW_COUNTER=$(($WINDOW_COUNTER+1))
write_window wait_load $WINDOW_COUNTER
}
write_window() {
#### Description: Writes in a specific window on a particular display.
#### Parameters: $1 - message to be written; $2 - display to be used.
#### DISPLAY_XORGS and ID_WINDOWS are declared in "multiseat-controller.sh".
export DISPLAY=${DISPLAY_XORGS[$2]}
case $1 in
ok)
$WRITE_MESSAGE ${ID_WINDOWS[$2]} "Monitor configurado, aguarde o restante ficar pronto" ;;
wait_load)
$WRITE_MESSAGE ${ID_WINDOWS[$2]} "Aguarde" ;;
press_key)
$WRITE_MESSAGE ${ID_WINDOWS[$2]} "Pressione a tecla F$(($2+1))" ;;
press_mouse)
$WRITE_MESSAGE ${ID_WINDOWS[$2]} "Pressione o botão esquerdo do mouse" ;;
esac
}
\ No newline at end of file
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment