lucine.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. blink() {
  3. time=$1
  4. delay=$2
  5. for i in $(seq 1 $time)
  6. do
  7. echo 1 > /sys/class/leds/input$INPUT::capslock/brightness
  8. echo 1 > /sys/class/leds/input$INPUT::scrolllock/brightness
  9. echo 1 > /sys/class/leds/input$INPUT::numlock/brightness
  10. sleep $delay
  11. echo 0 > /sys/class/leds/input$INPUT::capslock/brightness
  12. echo 0 > /sys/class/leds/input$INPUT::scrolllock/brightness
  13. echo 0 > /sys/class/leds/input$INPUT::numlock/brightness
  14. sleep $delay
  15. done
  16. }
  17. INPUT=$(ls /sys/class/leds/ | grep input[^0] | cut -d ':' -f 1 | sed 's/input//g' | head -n 1)
  18. if [[ ! -n $INPUT ]];
  19. then
  20. echo "You woot?"
  21. exit 1
  22. fi
  23. logger "lucine started on input $INPUT"
  24. blink 2 1
  25. pipe="/tmp/lucine"
  26. trap "rm -rf $pipe" EXIT
  27. if [[ ! -p $pipe ]];
  28. then
  29. mkfifo $pipe
  30. chmod 666 $pipe
  31. fi
  32. while :
  33. do
  34. if read line <$pipe;
  35. then
  36. command=$(echo $line | cut -f 1 -d ' ')
  37. case $command in
  38. blink)
  39. time=$(echo $line | cut -f 2 -d ' ')
  40. delay=$(echo $line | cut -f 3 -d ' ')
  41. blink $time $delay
  42. ;;
  43. quit)
  44. break;
  45. ;;
  46. *)
  47. ;;
  48. esac
  49. fi
  50. done