Advertisement
Guest User

displaylink-debian.sh

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