summaryrefslogtreecommitdiffstats
path: root/modules.d/slx-drm/hooks/s3-activate-nvidia-drivers.sh
blob: 28b0c639b56459a9fa449aa95ce82e09d4e3e65b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/ash

# hard check on nvidia graphic cards
cards="$( lspci -n | grep -o ' 03..: 10de:....' | awk '{print $2}' )"
if ! [ -d "/drm.cfg.d" ] && [ -n "$cards" ]; then
	echo "Failed to find '/drm.cfg.d', but have nvidia cards - will try nouveau."
	exit 1
fi
for card in $cards; do
	driver="$(awk '$1 = /'"$card"'/ {print $2; exit}'  /drm.cfg.d/*)"
	[ -z "$driver" ] && continue
	driver="${driver#'@'}"
	driver="${driver//-/\/}"
	driver_dir="/lib/modules/${driver}"
	[ -d "$driver_dir" ] || continue
	driver_target="/lib/modules/$(uname -r)/kernel/drivers/gpu/drm/nvidia"
	if [ -d "$driver_target" ]; then
		echo "'$driver_target' exists, will not overwrite!"
		exit 1
	fi
	# all good, move it over
	if ! mv "$driver_dir" "$driver_target" 2>&1; then
		echo "Failed to move '$driver_dir' to '$driver_target'."
		exit 1
	fi
	# finally run depmod to make it visible to udev
	if ! depmod -a 2>&1 ; then
		echo "Failed to run depmod, udev won't see the nvidia modules."
		exit 1
	fi
	# blacklist nouveau
	echo 'blacklist nouveau' > "/lib/modprobe.d/disable-nouveau.conf"
	echo "Initialized nvidia drivers."
	break
done

exit 0