#!/bin/sh

if [ -z "$2" ]
then 
	echo "usage: $0 textcommand Xcommand [name]"
	echo "example: $0 \"sudo loadkeys neo-de\" \"setxkbmap neo-de\" \"NEO\""
	exit 1
fi

if [ -n "$SSH_CONNECTION" ]
then
	echo "Dude, this is a ssh connection. I cannot change the keyboard setting here!"
	exit 1
fi

TEXT="Changing keyboard layout"

if [ -n "$3" ]
then	TEXT=$TEXT" to $3"
fi

if [ -z "$DISPLAY" ]
then 
	echo $TEXT", but I need root to do that!"
	eval $1
else
	echo $TEXT"."
	eval $2
fi
