Jon West | 7d88140 | 2021-04-15 08:42:42 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | dkms_name="openrazer-driver" # TODO Rename when dkms module is renamed. |
| 4 | |
| 5 | echo "This script will now try to determine why the razer driver isn't working correctly." |
| 6 | |
| 7 | # Step 1 - check if there is a razer device connected. |
| 8 | lsusb=$(lsusb | grep '1532:') |
| 9 | if [ -z "$lsusb" ]; then |
| 10 | echo "ERROR: Linux doesn't see any Razer device connected. Make sure it is connected! Exiting." |
| 11 | exit 1 |
| 12 | fi |
| 13 | |
| 14 | # Step 2 - check if a module is already loaded. |
| 15 | lsmod=$(lsmod | grep razer) |
| 16 | if [ -z "$lsmod" ]; then |
| 17 | echo "INFO: There is no kernel module loaded." |
| 18 | fi |
| 19 | |
| 20 | # Step 3 - check if the module can load correctly |
| 21 | echo "Please enter your 'sudo' password for privileged operations." |
| 22 | module_name="razerkbd" |
| 23 | modprobe=$(sudo modprobe $module_name 2>&1) |
| 24 | if [ $? != 0 ]; then |
| 25 | if [[ $modprobe == *"FATAL: Module $module_name not found"* ]]; then |
| 26 | echo "ERROR: The kernel module wasn't found. Trying to find out why." |
| 27 | dkms_status=$(sudo dkms status $dkms_name) |
| 28 | if [ -z "$dkms_status" ]; then |
| 29 | echo "ERROR: DKMS module isn't installed. Trying to install now." |
| 30 | dkms_version=$(cat /usr/src/$dkms_name-*/dkms.conf | grep PACKAGE_VERSION | cut -d '"' -f2) |
| 31 | # TODO Check error code on command "cat /usr/..." |
| 32 | dkms_install=$(sudo dkms install $dkms_name/$dkms_version) |
| 33 | if [ $? != 0 ]; then |
| 34 | if [[ $dkms_install == *"Error! Could not find module source directory."* ]]; then |
| 35 | echo "FATAL: Is the razer dkms package installed? Exiting." |
| 36 | exit 1 |
| 37 | elif [[ $dkms_install == *"Module openrazer-driver/$dkms_version already installed on kernel"* ]]; then |
| 38 | echo "FATAL: The dkms module is installed, but could not be loaded. Exiting." |
| 39 | exit 1 |
| 40 | fi |
| 41 | else |
| 42 | echo "INFO: dkms module should be installed now. Output of command:" |
| 43 | echo $dkms_install |
| 44 | echo "INFO: Please call the script again to check further. Exiting." |
| 45 | exit 0 |
| 46 | fi |
| 47 | fi |
| 48 | elif [[ $modprobe == *"ERROR: could not insert '$module_name': Required key not available"* ]]; then |
| 49 | echo "ERROR: The module couldn't be loaded due to secure boot being enabled. Please disable secure boot in your BIOS/UEFI and try again. Exiting." |
| 50 | exit 1 |
| 51 | else |
| 52 | echo "FATAL: Unknown error. The output will be echo'ed below. Exiting." |
| 53 | echo $modprobe |
| 54 | exit 1 |
| 55 | fi |
| 56 | fi |
| 57 | |
| 58 | # Step 4 - check the daemon |
| 59 | log_dir=/tmp/razer_logs |
| 60 | mkdir -p $log_dir |
| 61 | openrazer-daemon -r -v --log-dir=$log_dir |
| 62 | sleep 3 |
| 63 | daemon_output=$(cat $log_dir/razer.log) |
| 64 | if [ ! -z "$(echo $daemon_output | grep 'PermissionError: [Errno 13] Permission denied')" ]; then |
| 65 | echo "ERROR: The current user doesn't have permission to access the driver files. Checking why." |
| 66 | file=$(echo $daemon_output | cut -d "'" -f4) |
| 67 | owning_group=$(stat -c '%G' $file) |
| 68 | if [ $owning_group != "plugdev" ]; then |
| 69 | echo "FATAL: Because of some reason, the owner of the file isn't plugdev, as it should be. Exiting." |
| 70 | exit 1 |
| 71 | fi |
| 72 | group_plugdev=$(groups | grep plugdev) |
| 73 | if [ -z "$group_plugdev" ]; then |
| 74 | echo "FATAL: The current isn't member of the group 'plugdev'. Please fix this by running 'sudo gpasswd -a $USER plugdev'. Exiting." |
| 75 | exit 1 |
| 76 | fi |
| 77 | fi |
| 78 | |
| 79 | # Step 5 - check if the pylib sees the device(s) |
| 80 | pylib_len=$(python -c "from openrazer.client import DeviceManager; a = DeviceManager(); print(len(a.devices))") |
| 81 | if [ "$pylib_len" == 0 ]; then |
| 82 | echo "FATAL: The device was not recognized by the python library. Exiting." |
| 83 | exit 1 |
| 84 | fi |
| 85 | |
| 86 | # Everything alright (probably) |
| 87 | echo "The script didn't find an error. If you still think something's wrong, please create an issue on the GitHub page. Exiting." |
| 88 | exit 0 |