QWebchess work
[progcomp2013.git] / qchess_login.sh
1 #!/bin/bash
2
3 # Qchess login script
4 # Forces people to play Quantum Chess in order to login to a UCC clubroom machine
5 # (unless they work out that they can just press 'Q')
6
7 # Only works with GDM
8 # WARNING: Don't use on systems without GDM, because it will probably break everything
9 # NOTE: If you have users that never log out (ie: lock the screen instead), this won't be very effective
10
11 # Add to root's crontab to run every minute
12
13 # Check qchess isn't already running
14 if [ "$(ps aux | grep -v grep | grep "qchess\.py" | wc -l)" != "0" ]; then
15         echo "qchess already running" 1>&2
16         (ps aux | grep -v grep | grep qchess) 1>&2
17         exit 0
18 fi
19
20 # Check that only GDM is running gnome-session
21 # This should indicate that the login selection is being shown
22 session_types="gnome-session\|kdeinit"
23 non_gdm_sessions=$(ps aux | grep -v grep | grep "$session_types" | awk '{print $1}' | grep -v gdm | wc -l)
24
25 if [ "$non_gdm_sessions" != 0 ]; then
26         echo "$non_gdm_sessions non gdm sessions running" 1>&2
27         exit 0
28 fi
29
30 # OK, go ahead and do evil stuff
31
32 export DISPLAY=:1
33 p=$(pwd)
34 cd /home/wheel/matches/progcomp2013/qchess
35 win="black"
36
37 #espeak "I challenge you to a duel!"
38 while [ "$win" == "black" ]; do
39         # The game prevents the screen from sleeping automatically...
40         # The blackout option makes the game screen go black if no events happen
41         # It works on clownfish (OpenSUSE); the game is fullscreen. But not cabellera (Scientific Linux); the game isn't fullscreen
42         win=$(./qchess.py --blackout=600 @human @internal:AgentBishop)
43 done
44
45 #if [ "$win" == "white" ]; then
46 #       espeak "I'll beat you next time."
47 #else
48 #       espeak "You dirty, cheating, human."
49 #fi
50 cd $p

UCC git Repository :: git.ucc.asn.au