blob: 86ca6d99a612e1fdbd75f632225fa570c13a56f8 [file] [log] [blame]
Jon West7d881402021-04-15 08:42:42 -04001#!/bin/bash
2
3dkms_name="openrazer-driver" # TODO Rename when dkms module is renamed.
4
5echo "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.
8lsusb=$(lsusb | grep '1532:')
9if [ -z "$lsusb" ]; then
10 echo "ERROR: Linux doesn't see any Razer device connected. Make sure it is connected! Exiting."
11 exit 1
12fi
13
14# Step 2 - check if a module is already loaded.
15lsmod=$(lsmod | grep razer)
16if [ -z "$lsmod" ]; then
17 echo "INFO: There is no kernel module loaded."
18fi
19
20# Step 3 - check if the module can load correctly
21echo "Please enter your 'sudo' password for privileged operations."
22module_name="razerkbd"
23modprobe=$(sudo modprobe $module_name 2>&1)
24if [ $? != 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
56fi
57
58# Step 4 - check the daemon
59log_dir=/tmp/razer_logs
60mkdir -p $log_dir
61openrazer-daemon -r -v --log-dir=$log_dir
62sleep 3
63daemon_output=$(cat $log_dir/razer.log)
64if [ ! -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
77fi
78
79# Step 5 - check if the pylib sees the device(s)
80pylib_len=$(python -c "from openrazer.client import DeviceManager; a = DeviceManager(); print(len(a.devices))")
81if [ "$pylib_len" == 0 ]; then
82 echo "FATAL: The device was not recognized by the python library. Exiting."
83 exit 1
84fi
85
86# Everything alright (probably)
87echo "The script didn't find an error. If you still think something's wrong, please create an issue on the GitHub page. Exiting."
88exit 0