f92b770c65359dbf0a6a6885d0f691f5a2ae12c8
[live-config.git] / components / 1140-xserver-xorg
1 #!/bin/sh
2
3 ## live-config(7) - System Configuration Components
4 ## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
5 ##
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
9
10
11 set -e
12
13 Cmdline ()
14 {
15         for _PARAMETER in ${LIVE_CONFIG_CMDLINE}
16         do
17                 case "${_PARAMETER}" in
18                         live-config.keyboard-layouts=*|keyboard-layouts=*)
19                                 LIVE_KEYBOARD_LAYOUTS="${_PARAMETER#*keyboard-layouts=}"
20                                 ;;
21
22                         live-config.keyboard-model=*|keyboard-model=*)
23                                 LIVE_KEYBOARD_MODEL="${_PARAMETER#*keyboard-model=}"
24                                 ;;
25
26                         live-config.keyboard-options=*|keyboard-options=*)
27                                 LIVE_KEYBOARD_OPTIONS="${_PARAMETER#*keyboard-options=}"
28                                 ;;
29
30                         live-config.keyboard-variants=*|keyboard-variants=*)
31                                 LIVE_KEYBOARD_VARIANTS="${_PARAMETER#*keyboard-variants=}"
32                                 ;;
33
34                         live-config.xorg-xsession-manager=*|x-session-manager=*)
35                                 LIVE_X_SESSION_MANAGER="${_PARAMETER#*x-session-manager=}"
36                                 ;;
37
38                         live-config.xorg-driver=*|xorg-driver=*)
39                                 LIVE_XORG_DRIVER="${_PARAMETER#*xorg-driver=}"
40                                 ;;
41
42                         live-config.xorg-resolution=*|xorg-resolution=*)
43                                 LIVE_XORG_RESOLUTION="${_PARAMETER#*xorg-resolution=}"
44                                 ;;
45                 esac
46         done
47 }
48
49 Init ()
50 {
51         # Checking if package is installed
52         if [ ! -e /var/lib/dpkg/info/xserver-xorg.list ] || \
53            [ -e /var/lib/live/config/xserver-xorg ]
54         then
55                 exit 0
56         fi
57
58         echo -n " xserver-xorg"
59 }
60
61 Config ()
62 {
63         if [ -n "${LIVE_KEYBOARD_MODEL}" ]
64         then
65                 echo "xserver-xorg xserver-xorg/config/inputdevice/keyboard/model select ${LIVE_KEYBOARD_MODEL}" >> /tmp/live-config.cfg
66         fi
67
68         if [ -n "${LIVE_KEYBOARD_LAYOUTS}" ]
69         then
70                 echo "xserver-xorg xserver-xorg/config/inputdevice/keyboard/layout select ${LIVE_KEYBOARD_LAYOUTS}" >> /tmp/live-config.cfg
71         fi
72
73         if [ -n "${LIVE_KEYBOARD_VARIANTS}" ]
74         then
75                 echo "xserver-xorg xserver-xorg/config/inputdevice/keyboard/variant select ${LIVE_KEYBOARD_VARIANTS}" >> /tmp/live-config.cfg
76         fi
77
78         if [ -n "${LIVE_KEYBOARD_OPTIONS}" ]
79         then
80                 echo "xserver-xorg xserver-xorg/config/inputdevice/keyboard/options string ${LIVE_KEYBOARD_OPTIONS}" >> /tmp/live-config.cfg
81         fi
82
83         if [ -n "${LIVE_X_SESSION_MANAGER}" ]
84         then
85                 case "${LIVE_X_SESSION_MANAGER}" in
86                         none)
87                                 rm -f /etc/X11/default-display-manager
88                                 ;;
89
90                         *)
91                                 update-alternatives --quiet --set x-session-manager "${LIVE_X_SESSION_MANAGER}"
92                                 ;;
93                 esac
94         fi
95
96         if [ -z "${LIVE_XORG_DRIVER}" ] && [ -e /usr/bin/lspci ]
97         then
98                 # pci-id of the first graphic card
99                 _DEVICE="$(lspci -mn | awk '/0300/ { print $3$4 }' | sed -e 's|"||g' | tr [a-z] [A-Z] | head -n1)"
100
101                 if [ -n "${_DEVICE}" ]
102                 then
103                         if ls /usr/share/live/config/xserver-xorg/*.ids > /dev/null 2>&1
104                         then
105                                 # xorg-driver manual overrides
106                                 for _OVERRIDE_IDS in /usr/share/live/config/xserver-xorg/*.ids
107                                 do
108                                         if [ -e "${_OVERRIDE_IDS}" ]
109                                         then
110                                                 if grep -qs "${_DEVICE}" "${_OVERRIDE_IDS}"
111                                                 then
112                                                         LIVE_XORG_DRIVER="$(basename ${_OVERRIDE_IDS} .ids)"
113
114                                                         break
115                                                 fi
116                                         fi
117                                 done
118                         fi
119
120                         if [ -z "${LIVE_XORG_DRIVER}" ]
121                         then
122                                 # xorg-driver automatic override for virtualbox
123                                 if [ -e /var/lib/dpkg/info/virtualbox-guest-x11.list ] && echo "${_DEVICE}" | grep -qs '^80EEBEEF'
124                                 then
125                                         LIVE_XORG_DRIVER="vboxvideo"
126                                 fi
127
128                                 # xorg-driver automatic override for fglrx
129                                 if echo "${_DEVICE}" | grep -qs '^1002'
130                                 then
131                                         if grep -qs "${_DEVICE}" /usr/share/fglrx/fglrx.ids
132                                         then
133                                                 LIVE_XORG_DRIVER="fglrx"
134                                         fi
135                                 fi
136
137                                 # xorg-driver automatic override for nvidia
138                                 if echo "${_DEVICE}" | grep -qs -E '^(10DE|12D2)'
139                                 then
140                                         for _NVIDIA_IDS in /usr/lib/nvidia/current/nvidia.ids $(ls /usr/lib/nvidia/legacy-*/nvidia.ids | sort -V -r)
141                                         do
142                                                 if [ -e "${_NVIDIA_IDS}" ]
143                                                 then
144                                                         if grep -qs "${_DEVICE}" ${_NVIDIA_IDS}
145                                                         then
146                                                                 _NVIDIA_VERSION="$(basename $(dirname ${_NVIDIA_IDS}))"
147                                                                 _NVIDIA_MODULE="$(echo nvidia-${_NVIDIA_VERSION} | sed -e 's|-current$||')"
148
149                                                                 break
150                                                         fi
151                                                 fi
152                                         done
153
154                                         if [ -n "${_NVIDIA_VERSION}" ]
155                                         then
156                                                 LIVE_XORG_DRIVER="nvidia"
157                                         fi
158                                 fi
159                         fi
160                 fi
161         fi
162
163         if [ -n "${LIVE_XORG_DRIVER}" ]
164         then
165                 mkdir -p /etc/X11/xorg.conf.d
166
167                 if [ -e "/usr/share/live/config/xserver-xorg/${LIVE_XORG_DRIVER}.conf" ]
168                 then
169                         # xorg-driver manual override
170                         cp "/usr/share/live/config/xserver-xorg/${LIVE_XORG_DRIVER}.conf" /etc/X11/xorg.conf.d/zz-live-config_xserver-xorg.conf
171                 else
172
173                         # xorg-driver automatic override
174
175 cat > /etc/X11/xorg.conf.d/zz-live-config_xserver-xorg.conf << EOF
176 Section "Device"
177         Identifier      "Default screen"
178         Driver          "${LIVE_XORG_DRIVER}"
179 EndSection
180 EOF
181
182                 fi
183
184                 case "${LIVE_XORG_DRIVER}" in
185                         fglrx)
186                                 update-alternatives --quiet --set glx /usr/lib/fglrx
187
188                                 modprobe --ignore-install fglrx || true
189                                 ;;
190
191                         nvidia)
192                                 update-alternatives --quiet --set glx /usr/lib/nvidia
193                                 update-alternatives --quiet --set nvidia /usr/lib/nvidia/${_NVIDIA_VERSION:-current}
194
195                                 modprobe --ignore-install ${_NVIDIA_MODULE:-nvidia} || true
196                                 ;;
197
198                         *)
199                                 update-alternatives --quiet --set glx /usr/lib/mesa-diverted
200                                 ;;
201                 esac
202         fi
203
204         if [ -n "${LIVE_XORG_RESOLUTION}" ]
205         then
206                 echo "xrandr -s ${LIVE_XORG_RESOLUTION} || /bin/true" >> /etc/X11/Xsession.d/21xvidemode
207         else
208                 rm -f /etc/X11/Xsession.d/21xvidemode
209         fi
210
211         if [ -e /tmp/live-config.cfg ]
212         then
213                 debconf-set-selections < /tmp/live-config.cfg
214                 rm -f /tmp/live-config.cfg
215
216                 dpkg-reconfigure -f noninteractive -p critical \
217                         xserver-xorg 2>&1 \
218                         | grep -v "overwriting possibly-customised configuration" \
219                         | grep -v "file; backup in /etc/X11/xorg.conf" || true
220
221                 # Creating state file
222                 touch /var/lib/live/config/xserver-xorg
223         fi
224 }
225
226 Cmdline
227 Init
228 Config