razer-gamewrapper 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. [ -n "$RAZER_MOUSE_DEV" ] || RAZER_MOUSE_DEV=mouse
  3. [ -n "$RAZER_MOUSE_GAMINGPROF" ] || RAZER_MOUSE_GAMINGPROF=5
  4. usage()
  5. {
  6. echo "Usage razer-gamewrapper GAME [GAME-OPTIONS]"
  7. echo
  8. echo "Arguments:"
  9. echo " GAME is the game binary to execute"
  10. echo " GAME-OPTIONS are optional options to the game"
  11. echo
  12. echo "Environment variables:"
  13. echo " RAZER_MOUSE_DEV The id-string of the mouse."
  14. echo " Defaults to the first razer mouse."
  15. echo " RAZER_MOUSE_GAMINGPROF The profile ID of the gaming profile."
  16. echo " Defaults to '5'."
  17. }
  18. message()
  19. {
  20. echo "razer-gamewrapper: $*"
  21. }
  22. die()
  23. {
  24. message "$*"
  25. cleanup
  26. exit 1
  27. }
  28. cleanup()
  29. {
  30. [ -n "$oldprof" ] && {
  31. razercfg -d "$RAZER_MOUSE_DEV" -p "$oldprof" || die "Failed to reset mouse profile"
  32. }
  33. }
  34. terminate()
  35. {
  36. cleanup
  37. exit 1
  38. }
  39. oldprof=
  40. [ "$#" -eq 0 -o "$1" = "-h" -o "$1" = "--help" ] && { usage; terminate; }
  41. oldprof="$(razercfg -d "$RAZER_MOUSE_DEV" -P | awk '{print $3;}')"
  42. [ -n "$oldprof" ] || die "Failed to get current mouse profile"
  43. trap terminate INT TERM
  44. message "Old mouse profile: $oldprof"
  45. message "Switching to gaming profile: $RAZER_MOUSE_GAMINGPROF"
  46. razercfg -d "$RAZER_MOUSE_DEV" -p "$RAZER_MOUSE_GAMINGPROF" || die "Failed to set mouse gaming profile"
  47. message "Starting game: $*"
  48. $@ || die "Failed to start the game"
  49. message "Switching to old profile: $oldprof"
  50. cleanup
  51. exit 0