This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Hybrid Graphics Switcher

By: anion155 on Nov 11th, 2012  |  syntax: Bash  |  size: 4.39 KB  |  views: 1,633  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. ##
  3. # Author: Mikhaylov Anton aka Anion155 <anion155@gmail.com>
  4. ##
  5.  
  6. ## usage string
  7. USAGE="Usage: $0 [-d] [-r] [-h] \n\n
  8.         Script automaticaly installs fglrx driver.\n\n
  9.         -d Download new driver version.\n
  10.         -i Install (for Unity DE only) indicator for hybrid graphics switching maded by beidl <https://github.com/beidl/amd-indicator>.\n
  11.         -r Remove fglrx drivers.\n
  12.         -p Purge fglrx drivers and reinstall open_source drivers.\n\n
  13.         -q Quiet work.\n
  14.         -h This prompt.\n"
  15.  
  16. ## download new driver version
  17. DOWNLOAD_NEW=false
  18. DOWNLOAD_LAST_DRIVER_TYPE=b
  19.  
  20. ## quiet
  21. QUIET=false
  22.  
  23. ## install or update indicator for hybrid graphics switching
  24. INSTALL_INDICATOR=false
  25.  
  26. ## temp files directory
  27. TMP_FILES='/tmp/FGLRX_INSTALLER'
  28.  
  29. ## permanent files directory
  30. PERMANENT_FILES="`readlink -fn $(dirname $0)`/.fglrx"
  31.  
  32. ## check root privileges
  33. if [ `whoami` != 'root' ]; then
  34.         echo "E $0: Permission denied. Run $0 as the root"
  35.         exit 1;
  36. fi
  37.  
  38. ## cleaning procedure
  39. function clean {
  40.   cd /
  41.   echo 'Cleaning...'
  42.   rm -rf "$TMP_FILES"
  43. }
  44.  
  45. clean
  46. mkdir "$TMP_FILES"
  47.  
  48. ## remove current installed fglrx drivers
  49. remove_drv() {
  50.         sh /usr/share/ati/fglrx-uninstall.sh
  51.         _1=$?
  52.         apt-get remove --purge -y fglrx fglrx-amdcccle fglrx-dev fglrx-amdcccle-updates fglrx-updates fglrx-updates-dev
  53.         _2=$?
  54.         if [[ $_1 != 0 && $_2 != 0 ]]; then
  55.                 return 1
  56.         fi
  57.         return 0
  58. }
  59.  
  60. ## purge pieces of fglrx drivers and reinstall open-source drivers
  61. purge_drv() {
  62.         apt-get remove --purge -y xserver-xorg-video-ati xserver-xorg-video-radeon
  63.         apt-get install -y xserver-xorg-video-all
  64.         apt-get install --reinstall -y libgl1-mesa-glx libgl1-mesa-dri xserver-xorg-core
  65.         if [[ $? != 0 ]]; then
  66.                 apt-get install --reinstall -y libgl1-mesa-glx:i386 libgl1-mesa-glx:amd64 libgl1-mesa-dri:i386 libgl1-mesa-dri:amd64 xserver-xorg-core
  67.         fi
  68.         mv /etc/X11/xorg.conf{,.amd_fglrx-backup}
  69.         mv /etc/X11/xorg.conf{.clean_from_fglrx-backup,}
  70.         rm -rf /etc/ati
  71.         return 0
  72. }
  73.  
  74. ## what to do
  75. while getopts ":drpiqh" opt; do
  76.         case "$opt" in
  77.                 "d")
  78.                         DOWNLOAD_NEW=true;;
  79.                 "r")
  80.                         remove_drv
  81.                         if [[ $? != 0 ]]; then
  82.                                 echo "E $0: Error while removing fglrx drivers"
  83.                                 exit 1
  84.                         fi
  85.                         exit 0;;
  86.                 "p")
  87.                         remove_drv
  88.                         if [[ $? != 0 ]]; then
  89.                                 echo "E $0: Error while removing fglrx drivers"
  90.                                 exit 1
  91.                         fi
  92.                         purge_drv
  93.                         exit 0;;
  94.                 "i")
  95.                         INSTALL_INDICATOR=true;;
  96.                 "q")
  97.                         QUIET=true;;
  98.                 "h")
  99.                         echo -e $USAGE
  100.                         exit 0;;
  101.                 "?")
  102.                         echo "E $0: Invalid option $OPTARG. Try $0 -h for help"
  103.                         exit 1;;
  104.                 *)
  105.                         echo "E $0: Unknown error while processing options"
  106.                         exit 1;;
  107.         esac
  108. done
  109.  
  110. if $INSTALL_INDICATOR; then
  111.         PWD_=`pwd`
  112.         cd "$TMP_FILES"
  113.         IND_URL='https://github.com/beidl/amd-indicator'
  114.         git clone "$IND_URL" 'indicator/'
  115.         cd 'indicator'
  116.         if [[ `lsb_release -is` == 'Ubuntu' ]]; then
  117.                 wget 'https://www.dropbox.com/s/q8huhz4h9i3g4o6/amd-indicator_scripts.patch'
  118.                 patch -i 'scripts.patch'
  119.         fi
  120.         bash 'setup.sh'
  121.         cd $PWD_
  122. fi
  123.  
  124. if [ ! -f "$PERMANENT_FILES/fglrx.run" ]; then
  125.         DOWNLOAD_NEW=true
  126. fi
  127.  
  128. if $DOWNLOAD_NEW; then
  129.         ! $QUIET && read -p 'What type of driver do you want to use release or beta? <r|b>:' DOWNLOAD_LAST_DRIVER_TYPE
  130.         sed "/^DOWNLOAD_LAST_DRIVER_TYPE=/cDOWNLOAD_LAST_DRIVER_TYPE=$DOWNLOAD_LAST_DRIVER_TYPE"
  131.         PWD_=`pwd`
  132.         cd "$TMP_FILES"
  133.         wget -O page "http://support.amd.com/us/gpudownload/linux/Pages/radeon_linux.aspx"
  134.         sed -e '/Download</a>/!d' page --in-place
  135.         LINK_RELEASE=`sed -e '2d' -e 's/.*a href="\(.*\)$/\1/' page | cut -d\" -f1`
  136.         LINK_BETA=`sed -e '1d' -e 's/.*a href="\(.*\)$/\1/' page | cut -d\" -f1`
  137.         if [[ $DOWNLOAD_LAST_DRIVER_TYPE == 'r' ]]; then
  138.                 LINK=$LINK_RELEASE
  139.         elif [[ $DOWNLOAD_LAST_DRIVER_TYPE == 'b' ]]; then
  140.                 LINK=$LINK_BETA
  141.         fi
  142.         mkdir "$PERMANENT_FILES"
  143.         cd "$PERMANENT_FILES"
  144.         wget -O "`basename $LINK`" "$LINK"
  145.         unzip "`basename $LINK`"
  146.         mv "`basename $LINK | sed -e 's/zip$/run/'`" 'fglrx.run'
  147.         cd "$PWD_"
  148. fi
  149.  
  150. remove_drv
  151.  
  152. PWD_=`pwd`
  153. cd "$PERMANENT_FILES"
  154. apt-get install build-essential cdbs dh-make dkms execstack dh-modaliases linux-headers-generic
  155. if [ `uname -m` == 'x86_64' ]; then
  156.         apt-get install lib32gcc1
  157. fi
  158. fglrx.run --buildpkg "`lsb_release -is`/`lsb_release -cs`"
  159. if [[ $? == 0 ]]; then
  160.         dpkg -i fglrx*.deb
  161.         apt-get install -f
  162. else
  163.         echo 'Do not reboot computer, until this script ask you!'
  164.         fglrx.run
  165. fi
  166. cd /etc/X11/
  167. mv xorg.conf{,.clean_from_fglrx-backup}
  168. amdconfig --initial -f
  169. cp xorg.conf{,.amd_fglrx-backup}
  170. cd "$PWD_"
  171. exit 0
clone this paste RAW Paste Data