Commit 7e028b13 authored by Stephanie Briere Americo's avatar Stephanie Briere Americo
Browse files

SCRUM#357: Check for scripting failure and abort with error

parent e65eb9a2
Pipeline #14118 passed with stages
in 1 minute and 51 seconds
le-multiterminal (0.0.2) testing; urgency=medium
* Check for scripting failure and abort with error
-- Stephanie Briere Americo <sba16@c3sl.ufpr.br> Wed, 17 Jan 2018 09:32:42 -0200
le-multiterminal (0.0.1) testing; urgency=medium
* Initial release
......
#!/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: find-devices.sh
#### Description: Handles the event of a keyboard and associates the seat with the corresponding output.
#### Written by: Stephanie Briere Americo - sba16@c3sl.ufpr.br on 2017.
## Macros
DEVICES="/opt/le-multiterminal/devices" # shortcut to devices that have already been paired
CONF="/opt/le-multiterminal/98-xephyr-multi-seat.conf" # lightdm settings file (associates seat to output)
......@@ -9,60 +33,68 @@ READ_DEVICES="read-devices"
DETECT_KEYBOARDS="/opt/le-multiterminal/detect-keyboard.sh"
WRITE_W="write_window" # "window-acess.sh"
## Variables
## Variables
declare -a SEATS_LISTED # save the name of the existing seats
find_keyboard () {
fKey=$1
wNum=$(($fKey-1))
fKey=$1 # key that this script should expect to be pressed
wNum=$(($fKey-1)) # position in the window control vector
# List all existing seats
SEATS_LISTED=(seat0 $(loginctl list-seats | grep seat-))
CREATED=0
while (( ! CREATED )); do
KEYBOARDS=$($DETECT_KEYBOARDS)
# List all conected keyboards
for i in `ls $MDM_DEVICES | grep "\<keyboard"`; do
KEYBOARDS=$(sed "s#$i##g" <<< $KEYBOARDS)
done
# If no keyboard is connected, you can not proceed
if [ -z "$KEYBOARDS" ]; then
echo "No keyboards connected"
sleep 1
continue
echo "[Error] No keyboards connected"
exit 1
fi
# See if someone presses the key:
# See if someone presses the expected 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
# If $READ_DEVICES gets killed the script won't do bad stuff
if [ -z "$PRESSED" ]; then
continue
fi
# If the key has not yet been processed, continue to wait
if [ "$PRESSED" = 'timeout' ]; then
continue
fi
# If you got here, then the key was pressed
CREATED=1
# Creates a link to the keyboard so no one else can use it
ln -sf $PRESSED $DEVICES/keyboard_$fKey
# Check if there is no longer a link to this keyboard
for i in `ls $DEVICES | grep "\<keyboard"`; do
if [ "$i" != "keyboard_$fKey" ]; 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_$fKey
CREATED=0
fi
AUX=$(stat -c %N $DEVICES/$i | cut -d '>' -f2 | cut -d "'" -f2)
if [ "$AUX" = "$PRESSED" ]; then
# Keyboard link already exists, try again
rm -f $DEVICES/keyboard_$fKey
CREATED=0
fi
fi
done
done
# Find device address
SYS_DEV=/sys$(udevadm info $PRESSED | grep 'P:' | cut -d ' ' -f2- | sed -r 's/event.*$//g')
if [ -n "$SYS_DEV" ]; then
if [ -n "$SYS_DEV" ]; then
# Now we know the seat/output
SEAT_NAME=$(udevadm info -p $SYS_DEV | grep ID_SEAT | cut -d '=' -f2)
......@@ -80,8 +112,7 @@ find_keyboard () {
exit 0
else
echo "CAN NOT FIND KEYBOARD"
exit 1
echo "[Error] Can not find keyboard!"
exit 2
fi
}
\ No newline at end of file
}
......@@ -45,9 +45,11 @@ WRITE_WINDOW="write_window" # "window-acess.sh"
## Macros
FAKE_DISPLAY=:90 # display to access fake-seat (secondary card)
FAKE_SEAT="__fake-seat-1__"
OUTPUTS=("LVDS" "VGA") # output options
MAX_ATTEMPTS=100
## Variables
## Variables
WINDOW_ID_INIT=0 # if the onboard board, the start is 0; otherwise it is 1
WINDOW_COUNTER=0 # how many windows were created
N_SEATS_LISTED=0 # how many seats are there in the system
......@@ -65,11 +67,12 @@ create_onboard_window () {
Xorg ${DISPLAY_XORGS[$WINDOW_COUNTER]} &
pid=$!
# Guarantees the Xorg execution
xdpyinfo -display ${DISPLAY_XORGS[$WINDOW_COUNTER]}
EXIT_CODE=$?
while [[ $EXIT_CODE -ne 0 ]]; do
N_ATTEMPT=0
while [[ $EXIT_CODE -ne 0 ]]; do
sleep 0.5
xdpyinfo -display ${DISPLAY_XORGS[$WINDOW_COUNTER]}
EXIT_CODE=$?
......@@ -77,10 +80,17 @@ create_onboard_window () {
Xorg ${DISPLAY_XORGS[$WINDOW_COUNTER]} &
pid=$!
fi
if [[ $N_ATTEMPT -gt $MAX_ATTEMPTS ]]; then
echo "[Error] Run Xorg ${DISPLAY_XORGS[$WINDOW_COUNTER]} failed."
exit 1
fi
N_ATTEMPT=$(($N_ATTEMPT+1))
done
$CREATE_WINDOW
ONBOARD=1
else
WINDOW_ID_INIT=1
......@@ -91,7 +101,7 @@ create_onboard_window () {
create_secundarycard_windows () {
# The fake_seat display needs to be exported to run the Xephyr that communicate with it
export DISPLAY=$FAKE_DISPLAY
for i in ${OUTPUTS[*]}; do
# Display for each output
DISPLAY_XORGS[$WINDOW_COUNTER]=:$((WINDOW_COUNTER+10))
......@@ -99,11 +109,12 @@ create_secundarycard_windows () {
# Run Xephyr to type in this output
Xephyr ${DISPLAY_XORGS[$WINDOW_COUNTER]} -output $i -noxv &
pid=$!
# Guarantees the Xephyr execution
xdpyinfo -display ${DISPLAY_XORGS[$WINDOW_COUNTER]}
EXIT_CODE=$?
while [[ $EXIT_CODE -ne 0 ]]; do
N_ATTEMPT=0
while [[ $EXIT_CODE -ne 0 ]]; do
sleep 0.5
xdpyinfo -display ${DISPLAY_XORGS[$WINDOW_COUNTER]}
EXIT_CODE=$?
......@@ -111,11 +122,18 @@ create_secundarycard_windows () {
Xephyr ${DISPLAY_XORGS[$WINDOW_COUNTER]} -output $i -noxv &
pid=$!
fi
if [[ $N_ATTEMPT -gt $MAX_ATTEMPTS ]]; then
echo "[Error] Run Xephyr ${DISPLAY_XORGS[$WINDOW_COUNTER]} failed."
exit 1
fi
N_ATTEMPT=$(($N_ATTEMPT+1))
done
# 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
......@@ -143,25 +161,35 @@ kill_jobs () {
rm -rf $MC3SL_DEVICES/
fi
rm -rf $MC3SL_DEVICES
pkill -P $$
}
############ BEGIN ############
# Guarantees the fake-seat execution, used to access the secondary board
Xorg $FAKE_DISPLAY -seat __fake-seat-1__ -dpms -s 0 -nocursor &
Xorg $FAKE_DISPLAY -seat $FAKE_SEAT -dpms -s 0 -nocursor &
pid=$!
xdpyinfo -display $FAKE_DISPLAY
EXIT_CODE=$?
while [[ $EXIT_CODE -ne 0 ]]; do
N_ATTEMPT=0
while [[ $EXIT_CODE -ne 0 ]]; do
sleep 0.5
xdpyinfo -display $FAKE_DISPLAY
EXIT_CODE=$?
if ! kill -0 "${pid}" >/dev/null 2>&1; then
Xorg $FAKE_DISPLAY -seat __fake-seat-1__ -dpms -s 0 -nocursor &
Xorg $FAKE_DISPLAY -seat $FAKE_SEAT -dpms -s 0 -nocursor &
pid=$!
fi
if [[ $N_ATTEMPT -gt $MAX_ATTEMPTS ]]; then
echo "[Error] Run Xorg $FAKE_DISPLAY -seat $FAKE_SEAT failed."
exit 1
fi
N_ATTEMPT=$(($N_ATTEMPT+1))
done
# If the onboard is connected, it creates a window to write on the screen
......@@ -173,18 +201,23 @@ create_secundarycard_windows
# We'll use it to save a shortcut to devices that have already been paired
mkdir -p $MC3SL_DEVICES
# Run configuration script for each seat
# Run configuration script for each seat
configure_devices
# Wait until all seats are configured
N_SEATS_LISTED=$(($(loginctl list-seats | grep -c "seat-")+$ONBOARD))
CONFIGURED_SEATS=0
while [[ $CONFIGURED_SEATS -lt $N_SEATS_LISTED ]]; do
wait -n ${PID_FIND_DEVICES[*]}
EXIT_CODE=$?
if [[ $EXIT_CODE -eq 0 ]]; then
wait -n ${PID_FIND_DEVICES[*]}
EXIT_CODE=$?
if [[ $EXIT_CODE -eq 0 ]]; then
CONFIGURED_SEATS=$(($CONFIGURED_SEATS+1))
else if [[ $EXIT_CODE -eq 2 ]]; then
echo "[Error] Can not configure output: find-devices.sh failed."
rm -f $MC3SL_CONF
exit 1
fi
fi
done
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment