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