forked from AdnanHodzic/displaylink-debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplaylink-debian.sh
executable file
·434 lines (387 loc) · 10.1 KB
/
displaylink-debian.sh
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/bin/bash
#
# displaylink-debian:
# DisplayLink driver installer for Debian/Ubuntu based Linux distributions.
#
# Supported platforms: Debian GNU/Linux, Ubuntu, Elementary OS, Mint, Kali
#
# Blog post: http://foolcontrol.org/?p=1777
#
# Copyleft: Adnan Hodzic <[email protected]>
# License: GPLv3
# define the version to get as the latest available version
version=`wget -q -O - http://www.displaylink.com/downloads/ubuntu | grep "download-version" | head -n 1 | perl -pe '($_)=/([0-9]+([.][0-9]+)+)/'`
# define download url to be the correct version
dlurl="http://www.displaylink.com/"`wget -q -O - http://www.displaylink.com/downloads/ubuntu | grep "download-link" | head -n 1 | perl -pe '($_)=/<a href="\/([^"]+)"[^>]+class="download-link"/'`
driver_dir=$version
separator(){
sep="\n-------------------------------------------------------------------"
echo -e $sep
}
root_check(){
# root check
if (( $EUID != 0 ));
then
separator
echo -e "\nMust be run as root (i.e: 'sudo $0')."
separator
exit 1
fi
}
# Dependencies
if [ "$lsb" == "Deepin" ];
then
deps=(unzip linux-headers-$(uname -r)-deepin dkms lsb-release linux-source-deepin)
else
deps=(unzip linux-headers-$(uname -r) dkms lsb-release linux-source)
fi
dep_check() {
echo -e "\nChecking dependencies\n"
for dep in ${deps[@]}
do
if ! dpkg -s $dep | grep "Status: install ok installed" > /dev/null 2>&1
then
default=y
read -p "$dep not found! Install? [Y/n] " response
response=${response:-$default}
if [[ $response =~ ^(yes|y|Y)$ ]]
then
if ! apt-get install $dep
then
echo "$dep installation failed. Aborting."
exit 1
fi
else
separator
echo -e "\nCannot continue without $dep. Aborting."
separator
exit 1
fi
else
echo "$dep is installed"
fi
done
}
distro_check(){
separator
# RedHat
if [ -f /etc/redhat-release ];
then
echo "This is a Redhat based distro ..."
# ToDo:
# Add platform type message for RedHat
exit 1
else
# Confirm dependencies are in place
dep_check
# Checker parameters
lsb="$(lsb_release -is)"
codename="$(lsb_release -cs)"
platform="$(lsb_release -ics | sed '$!s/$/ /' | tr -d '\n')"
# Unsupported platform message
message(){
echo -e "\n---------------------------------------------------------------\n"
echo -e "Unsuported platform: $platform"
echo -e ""
echo -e "This tool is Open Source and feel free to extend it"
echo -e "GitHub repo: https://github.com/AdnanHodzic/displaylink-debian/"
echo -e "\n---------------------------------------------------------------\n"
}
# Ubuntu
if [ "$lsb" == "Ubuntu" ];
then
if [ $codename == "trusty" ] || [ $codename == "vivid" ] || [ $codename == "wily" ] || [ $codename == "xenial" ] || [ $codename == "yakkety" ] || [ $codename == "zesty" ] || [ $codename == "artful" ] || [ $codename == "bionic" ] || [ $codename == "cosmic" ];
then
echo -e "\nPlatform requirements satisfied, proceeding ..."
else
message
exit 1
fi
# elementary OS
elif [ "$lsb" == "elementary OS" ] || [ "$lsb" == "elementary" ];
then
if [ $codename == "freya" ] || [ $codename == "loki" ];
then
echo -e "\nPlatform requirements satisfied, proceeding ..."
else
message
exit 1
fi
# Debian
elif [ "$lsb" == "Debian" ];
then
if [ $codename == "jessie" ] || [ $codename == "stretch" ] || [ $codename == "sid" ] || [ $codename == "buster" ] || [ $codename == "n/a" ] ;
then
echo -e "\nPlatform requirements satisfied, proceeding ..."
else
message
exit 1
fi
# Mint
elif [ "$lsb" == "LinuxMint" ];
then
if [ $codename == "sarah" ] || [ $codename == "rosa" ] || [ $codename == "petra" ] || [ $codename == "olivia" ] || [ $codename == "serena" ] || [ $codename == "sonya" ] || [ $codename == "sylvia" ] || [ $codename == "tara" ];
then
echo -e "\nPlatform requirements satisfied, proceeding ..."
else
message
exit 1
fi
# Kali
elif [ "$lsb" == "Kali" ];
then
if [ $codename == "kali-rolling" ] || [ $codename == "2016.2" ] || [ $codename == "2017.3" ];
then
echo -e "\nPlatform requirements satisfied, proceeding ..."
else
message
exit 1
fi
# Deepin
elif [ "$lsb" == "Deepin" ];
then
if [ $codename == "unstable" ];
then
echo -e "\nPlatform requirements satisfied, proceeding ..."
else
message
exit 1
fi
# Deepin
elif [ "$lsb" == "Nitrux" ];
then
if [ $codename == "nxos" ];
then
echo -e "\nPlatform requirements satisfied, proceeding ..."
else
message
exit 1
fi
else
message
exit 1
fi
fi
}
sysinitdaemon_get(){
sysinitdaemon="systemd"
if [ "$lsb" == "Ubuntu" ];
then
if [ $codename == "trusty" ];
then
sysinitdaemon="upstart"
fi
# Elementary
elif [ "$lsb" == "elementary OS" ];
then
if [ $codename == "freya" ];
then
sysinitdaemon="upstart"
fi
fi
echo $sysinitdaemon
}
clean_up(){
# remove obsolete/redundant files which can only hamper reinstalls
separator
echo -e "\nPerforming clean-up"
# go back to displaylink-debian
cd - &> /dev/null
if [ -f "DisplayLink_Ubuntu_$version.zip" ]
then
echo "Removing redundant: \"DisplayLink_Ubuntu_$version.zip\" file"
rm "DisplayLink_Ubuntu_$version.zip"
fi
if [ -d $driver_dir ]
then
echo "Removing redundant: \"$driver_dir\" directory"
rm -r $driver_dir
fi
}
download() {
local dlfileid=$(echo $dlurl | perl -pe '($_)=/.+\?id=(\d+)/')
echo -en "\nPlease read the Software License Agreement\navailable at $dlurl\nand accept here: [Y]es or [N]o: "
read ACCEPT
case $ACCEPT in
y*|Y*)
echo -e "\nDownloading DisplayLink Ubuntu driver:\n"
wget -O DisplayLink_Ubuntu_${version}.zip "--post-data=fileId=$dlfileid&accept_submit=Accept" $dlurl
# make sure we got the file downloadet before continueing
if [ $? -ne 0 ]
then
echo -e "\nUnable to download Displaylink driver\n"
exit
fi
;;
*)
echo "Can't download the driver without accepting the license agreement!"
exit 1
;;
esac
}
install(){
separator
download
# prep
mkdir $driver_dir
separator
echo -e "\nPreparing for install\n"
test -d $driver_dir && /bin/rm -Rf $driver_dir
unzip -d $driver_dir DisplayLink_Ubuntu_${version}.zip
chmod +x $driver_dir/displaylink-driver-${version}.[0-9]*.run
./$driver_dir/displaylink-driver-${version}.[0-9]*.run --keep --noexec
mv displaylink-driver-${version}.[0-9]*/ $driver_dir/displaylink-driver-${version}
# get sysinitdaemon
sysinitdaemon=$(sysinitdaemon_get)
# modify displaylink-installer.sh
sed -i "s/SYSTEMINITDAEMON=unknown/SYSTEMINITDAEMON=$sysinitdaemon/g" $driver_dir/displaylink-driver-${version}/displaylink-installer.sh
if [ "$lsb" == "Debian" ] || [ "$lsb" == "Kali" ] || [ "$lsb" == "Deepin" ];
then
sed -i 's#/lib/modules/$KVER/build/Kconfig#/lib/modules/$KVER/build/scripts/kconfig/conf#g' $driver_dir/displaylink-driver-${version}/displaylink-installer.sh
ln -s /lib/modules/$(uname -r)/build/Makefile /lib/modules/$(uname -r)/build/Kconfig
fi
# install
separator
echo -e "\nInstalling driver version: $version\n"
cd $driver_dir/displaylink-driver-${version} && ./displaylink-installer.sh install
}
# post install
post_install(){
separator
echo -e "\nPerforming post install steps\n"
# fix: issue #42 (dlm.service can't start)
# note: for this to work libstdc++6 package needs to be installed from >= Stretch
if [ "$lsb" == "Debian" ] || [ "$lsb" == "Kali" ];
then
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /opt/displaylink/libstdc++.so.6
fi
# fix: issue #36 (can't enable dlm.service)
sed -i "/RestartSec=5/a[Install]\nWantedBy=multi-user.target" /lib/systemd/system/dlm.service
sudo systemctl enable dlm.service
# disable pageflip for modesetting
modesetting(){
mkdir -p /etc/X11/xorg.conf.d
cat > /etc/X11/xorg.conf.d/20-displaylink.conf <<EOL
Section "Device"
Identifier "DisplayLink"
Driver "modesetting"
Option "PageFlip" "false"
EndSection
EOL
chown root: /etc/X11/xorg.conf.d/20-displaylink.conf
chmod 644 /etc/X11/xorg.conf.d/20-displaylink.conf
}
function ver2int {
echo "$@" | awk -F "." '{ printf("%03d%03d%03d\n", $1,$2,$3); }';
}
xorg_vcheck="$(dpkg -l | grep "ii xserver-xorg-core" | awk '{print $3}' | sed 's/[^,:]*://g')"
min_xorg=1.18.3
if [ "$(ver2int $xorg_vcheck)" -gt "$(ver2int $min_xorg)" ];
then
echo "Disabling PageFlip for modesetting"
modesetting
else
echo "No need to disable PageFlip for modesetting"
fi
}
# uninstall
uninstall(){
separator
echo -e "\nUninstalling ...\n"
# displaylink-installer uninstall
if [ "$lsb" == "Debian" ] || [ "$lsb" == "Kali" ];
then
rm /lib/modules/$(uname -r)/build/Kconfig
fi
# double check if evdi module is loaded, if yes remove it
evdi_module="evdi"
if lsmod | grep "$evdi_module" &> /dev/null ; then
echo "Removing $evdi_module module"
rmmod evdi
fi
# remove modesetting file
if [ -f "/etc/X11/xorg.conf.d/20-displaylink.conf" ]
then
echo "Removing disabled PageFlip for modesetting"
rm "/etc/X11/xorg.conf.d/20-displaylink.conf"
fi
}
# interactively asks for operation
ask_operation(){
echo -e "\n--------------------------- displaylink-debian ----------------------------"
echo -e "\nDisplayLink driver installer for Debian based Linux distributions:\n"
echo -e "* Debian GNU/Linux"
echo -e "* Ubuntu"
echo -e "* Elementary OS"
echo -e "* Linux Mint"
echo -e "* Kali Linux"
echo -e "* Deepin"
echo -e "* Nitrux"
echo -e "\nOptions:\n"
read -p "[I]nstall
[U]ninstall
[R]e-install
[Q]uit
Select a key: [i/u/r/q]: " answer
}
root_check
if [[ -z "${1}" ]];
then
ask_operation
else
case "${1}" in
"--install")
answer="i"
;;
"--uninstall")
answer="u"
;;
"--reinstall")
answer="r"
;;
*)
answer="n"
;;
esac
fi
if [[ $answer == [Ii] ]];
then
distro_check
install
post_install
clean_up
separator
echo -e "\nInstall complete, please reboot to apply the changes"
separator
echo ""
elif [[ $answer == [Uu] ]];
then
distro_check
uninstall
clean_up
separator
echo -e "\nUninstall complete"
separator
echo ""
elif [[ $answer == [Rr] ]];
then
distro_check
uninstall
clean_up
distro_check
install
post_install
clean_up
separator
echo -e "\nRe-install complete, please reboot to apply the changes"
separator
echo ""
elif [[ $answer == [Qq] ]];
then
separator
echo ""
exit 0
else
echo -e "\nWrong key, aborting ...\n"
exit 1
fi