qchess_login.sh 1.6 KB
Newer Older
Sam Moore's avatar
Sam Moore committed
1 2 3
#!/bin/bash

# Qchess login script
Sam Moore's avatar
Sam Moore committed
4 5 6
# Forces people to play Quantum Chess in order to login to a UCC clubroom machine
# (unless they work out that they can just press 'Q')

Sam Moore's avatar
Sam Moore committed
7 8
# Only works with GDM
# WARNING: Don't use on systems without GDM, because it will probably break everything
Sam Moore's avatar
Sam Moore committed
9 10
# NOTE: If you have users that never log out (ie: lock the screen instead), this won't be very effective

Sam Moore's avatar
Sam Moore committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# Add to root's crontab to run every minute

# Check qchess isn't already running
if [ "$(ps aux | grep -v grep | grep "qchess\.py" | wc -l)" != "0" ]; then
	echo "qchess already running" 1>&2
	(ps aux | grep -v grep | grep qchess) 1>&2
	exit 0
fi

# Check that only GDM is running gnome-session
# This should indicate that the login selection is being shown
session_types="gnome-session\|kdeinit"
non_gdm_sessions=$(ps aux | grep -v grep | grep "$session_types" | awk '{print $1}' | grep -v gdm | wc -l)

if [ "$non_gdm_sessions" != 0 ]; then
	echo "$non_gdm_sessions non gdm sessions running" 1>&2
	exit 0
fi

# OK, go ahead and do evil stuff

export DISPLAY=:1
p=$(pwd)
cd /home/wheel/matches/progcomp2013/qchess
win="black"

#espeak "I challenge you to a duel!"
while [ "$win" == "black" ]; do
Sam Moore's avatar
Sam Moore committed
39 40 41 42
	# The game prevents the screen from sleeping automatically...
	# The blackout option makes the game screen go black if no events happen
	# It works on clownfish (OpenSUSE); the game is fullscreen. But not cabellera (Scientific Linux); the game isn't fullscreen
	win=$(./qchess.py --blackout=600 @human @internal:AgentBishop)
Sam Moore's avatar
Sam Moore committed
43 44 45 46 47 48 49 50
done

#if [ "$win" == "white" ]; then
#	espeak "I'll beat you next time."
#else
#	espeak "You dirty, cheating, human."
#fi
cd $p