#!/bin/sh #lock {on|off|init|warn} #locks the screen! #init: does not executes pre and post scripts and # make everything ready to use lock. #no parameter: simply locks the screen #on, off: Turns locking on and off #warn: warns with dialog before locking #return values: #0: everything went ok #1: was already locked #2: locked, but not found lockfile (found lock process) #3: automatic locking manually disabled #4: found process which prevent automatic locking # (e.g. video running, programm defined in ~/.nolock) #5: Manually prevented automatic locking once #needs: a lot of things #if you arent a bash scripter, you wont #have fun with lock! #Environment export PATH="/bin:/usr/bin:/usr/bin/X11" export DISPLAY=":0.0" export USER=`whoami` #Files INIT="/tmp/init_$UID" LOCK="/tmp/lock_$UID" DONT="/tmp/dont_$UID" NOLOCK="/home/$USER/.nolock" PRELOCK="/home/$USER/.prelock" POSTLOCK="/home/$USER/.postlock" if [ "$1" = "init" ] then touch $INIT /bin/rm -f $LOCK /bin/rm -f $DONT fi if [ -f $LOCK ] then echo "Already locked" exit 1 fi if [ ! -f $INIT ] then echo "Run lock init first" exit 1 fi #PC befindet sich im lock-Modus touch $LOCK #remove all queues of at OLD_LOCKS=`atq -q l | awk '{print $1}'` if [ "$OLD_LOCKS" ] then atrm $OLD_LOCKS fi #check again (just in case!) for i in `pgrep -x lock` do # another lock process found if [ "$i" != "$$" ] then # you init the whole thing, kill it if [ "$1" = "init" ] then kill "$i" else exit 2 fi fi done #Cleans up #Exits with Exit Code $1 cleanup () { #Delete all locks again and generate a new one in 30 min atrm `atq -q l | awk '{print $1}'` &> /dev/null echo 'lock warn &> /dev/null' | at -q l now +30 min &> /dev/null # Unlock rm -f $LOCK exit $1 } #these options are to set or delete #the dont_lock flag. #It is used in the warn_lock, and #it wont automatically lock the #screen if it set. #This is for watching TV or if you #dont want to be disturbed. #there might be one parameter #possible Values are warn, off or on if [ "$1" = "warn" ] then #warn is for automatically locking #It first puts a message, that it will lock #it will not lock, if dont_lock flag is set! #dont_lock ? if [ -f $DONT ] then echo "Darf nicht automatisch gesperrt werden" rm -f $LOCK cleanup 3 fi # all applications listed inside this file prevent locking. if [ -f $NOLOCK ] then for i in `cat $NOLOCK` do pgrep -u $USER "$i" && cleanup 4 done fi #notify play /usr/share/sounds/KDE_Notify.wav &> /dev/null #kdialog starten kdialog --sorry "Lock screen" &> /dev/null & PID_KDIALOG=$! sleep 18 #uncomment next lines to make it possible to avoid locking #if ! /bin/kill $PID_KDIALOG &> /dev/null #then # cleanup 5 #fi elif [ "$1" = "off" ] then touch $DONT rm -f $LOCK exit 0 elif [ "$1" = "on" ] then rm -f $DONT rm -f $LOCK exit 0 fi #pre locking script if [ "$1" != "init" ] then #Stops the current song (not good!) #xmms -s #Pauses the current Song #if xmmsctrl paused #then # echo "is paused" #else # xmmsctrl pause #fi #set icq away #echo status away > /home/markus/.licq/licq_fifo & #dcop kopete KopeteIface setAway if [ -f $PRELOCK ] then . $PRELOCK fi #/usr/bin/fetch &> /dev/null & # this sleep is necessary to not immediately wakeup # the dpms again sleep 1 fi #blank screen xset dpms force off #Locks the Screen the kde-way #Attention: Will walk through in script (postlock done immediately) #dcop kdesktop KScreensaverIface lock #Locks the Screen the xlock-way RV="1" while [ "$RV" -ne "0" ] do xtrlock &> /dev/null RV=$? # try as long as return value not 0 done #post scripts if [ "$i" != "init" ] then #run music #if xmmsctrl paused #then # xmmsctrl play &> /dev/null #fi #set icq online #echo status online > /home/markus/.licq/licq_fifo & #dcop kopete KopeteIface setAvailable if [ -f $POSTLOCK ] then . $POSTLOCK fi fi cleanup 0