summarylogtreecommitdiffstats
path: root/autofglrx.sh
blob: c721893bffdb5cced5dc199a68c8040ab02a416d (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions



LOG="/var/log/catalyst-install.log"

kernel=$(uname -r)
if [ -d "/usr/lib/modules/${kernel}" ]; then
	where_modules="usr/lib/modules"
	elif [ -d "/lib/modules/${kernel}" ]; then
		where_modules="lib/modules"
fi


build_fglrx() {
	rmmod fglrx >/dev/null 2>&1
	/usr/bin/catalyst_build_module "${kernel}" >/dev/null 2>&1
	/usr/bin/catalyst_build_module remove &>> $LOG
	
	
	if [ $? -ne 0 ]
	then
		stat_append "ERROR: see ${LOG} for details"
		stat_die
	fi
}


check_fglrx() {
	compare=$(uname -v)

	if [[ -e /${where_modules}/${kernel}/video/fglrx.ko ]] || [[ -e /${where_modules}/${kernel}/extramodules/fglrx.ko ]] || [[ -e /${where_modules}/${kernel}/video/fglrx.ko.gz ]] || [[ -e /${where_modules}/${kernel}/extramodules/fglrx.ko.gz ]]
	then
		  test=$(modinfo -F description fglrx | grep "__unv:") || stat_die
	else
		return 0
	fi

	if [ "$test" != "__unv:$compare" ]
	then
		return 0
	else
		return 1
	fi
}


load_fglrx() {
	stat_append ": Loading fglrx"
	modprobe fglrx

	if [ $? -ne 0 ]
	then
		stat_die
	else
		stat_done
	fi
}



case "$1" in
  	start)
		stat_busy "Checking fglrx"
		
		
		check_fglrx
		
		if [ $? -eq 0 ]
		then
			stat_append ": Building fglrx "
			build_fglrx
		fi
		
		
		load_fglrx
	;;
	
	stop)
		stat_busy "Unloading fglrx"
		
		
		rmmod fglrx
		
		if [ $? -ne 0 ]
		then
			stat_fail
		else
			stat_done
		fi
	;;
	
	restart)
		$0 stop
		sleep 1
		$0 start
    ;;

	status)
		if [ -n "$(lsmod | grep fglrx)" ]
		then
			stat_busy "Module fglrx is loaded"
			stat_done
		else
			stat_busy "Module fglrx is not loaded"
			stat_fail
		fi
	;;

  	*)
    	echo "Usage: $0 {start|stop|restart|status}"
esac