gl-select 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/bin/bash
  2. #
  3. # gl-select: select active gl/glx libraries/extensions
  4. #
  5. infoUsage() {
  6. echo "Usage: $(basename $0) [ status | use [xorg|nvidia|ati] ]"
  7. exit 0
  8. }
  9. infoMissing() {
  10. echo "One or more of the non-xorg gl/glx backup files are missing."
  11. echo "This means either you're not using a non-xorg gl/glx setup, in which"
  12. echo "case nothing needs to be changed, OR your xorg backups are missing,"
  13. echo "which can be solved by reinstalling xorg-server and mesa3d packages."
  14. echo
  15. echo "Files:"
  16. getMissBackups
  17. exit 1
  18. }
  19. infoRevert() {
  20. echo "You appear to already be using a non-xorg gl/glx setup. Check that by"
  21. echo "using 'gl-select status', OR if the one selected isn't the correct one,"
  22. echo "revert to xorg and then select the correct new setup using:"
  23. echo "'gl-select use xorg; gl-select use <new gl/glx>'."
  24. echo
  25. echo "Files:"
  26. getExistBackups
  27. exit 1
  28. }
  29. infoOldStuff() {
  30. echo "You appear to be using a non-xorg gl/glx setup. You should revert your"
  31. echo "selection to xorg and then select the correct new setup, but seems you"
  32. echo "are using the old stuff setup due to gl-select 1.3, so you need to use"
  33. echo "something like:"
  34. echo "'gl-select use xorg --old-stuff; gl-select use <new gl/glx>'."
  35. exit 1
  36. }
  37. checkInstalled() {
  38. # checks either a single port or list of ports
  39. local notInstalled=1
  40. for arg in $@; do
  41. if [ -d "/var/lib/pkg/DB/$arg" ]; then
  42. notInstalled=0
  43. fi
  44. done
  45. if [ $notInstalled -eq 1 ]; then
  46. if [ $# -eq 1 ]; then
  47. echo "$arg isn't installed!"
  48. else
  49. echo "None of the following ports are installed! (one is required)"
  50. for i in $@; do echo " $i"; done
  51. fi
  52. exit 1
  53. fi
  54. }
  55. getMissBackups() {
  56. # get missing xorg backup'ed files
  57. for b in $BACKUPS; do if [ ! -f $b ]; then echo $b; fi; done
  58. }
  59. getExistBackups() {
  60. # get existing xorg backup'ed files
  61. for b in $BACKUPS; do if [ -f $b ]; then echo $b; fi; done
  62. }
  63. doGLsymlinks() {
  64. [ ! -L /usr/lib/libGL.so.1 ] && ln -sf libGL.so.1.2 /usr/lib/libGL.so.1
  65. [ ! -L /usr/lib/libGL.so ] && ln -sf libGL.so.1 /usr/lib/libGL.so
  66. return 0
  67. }
  68. doStatus() {
  69. # check which selection its being used
  70. local file=$(file -h /usr/lib/libGL.so.1.2.0 | awk '{ if (/symbolic link/) print $5; else print $1; }' | sed 's|:||')
  71. case $file in
  72. *libGL.so.1.2.0) echo "* xorg gl/glx is selected" ;;
  73. *libGL_so_1_2_nvidia) echo "* nvidia gl/glx is selected" ;;
  74. *libGL_so_1_2_ati) echo "* ati gl/glx is selected" ;;
  75. *) echo "unsupported: $file"; infoOldStuff ;;
  76. esac
  77. }
  78. doUse() {
  79. # perform the selection for the following supported gl/glx setups
  80. local selection=$1
  81. local options=$2
  82. [ -z "$selection" ] && infoUsage
  83. case $selection in
  84. "xorg")
  85. [ "$options" == "--old-stuff" ] && oldStuff
  86. # check for missing xorg backup'ed files
  87. local mbackups="$(getMissBackups)"
  88. [ ! -z "$mbackups" ] && infoMissing $mbackups
  89. # switch to xorg stuff
  90. (
  91. # libglx
  92. rm -f /usr/lib/xorg/modules/extensions/libglx.so
  93. mv /usr/lib/xorg/modules/extensions/libglx{_so,.so}
  94. # libGL
  95. rm -f usr/lib/libGL.so.1.2.0
  96. mv /usr/lib/libGL{_so_1_2,.so.1.2.0}
  97. doGLsymlinks
  98. ) && echo "* xorg gl/glx selected"
  99. ;;
  100. "nvidia")
  101. # is an nvidia port installed?
  102. checkInstalled nvidia nvidia-sl nvidia-legacy-96xx nvidia-legacy-71xx
  103. # check for the existence of xorg backups
  104. local ebackups="$(getExistBackups)"
  105. [ ! -z "$ebackups" ] && infoRevert $ebackups
  106. # switch to nvidia stuff
  107. # conflicting files which ati provides:
  108. # libglx_so_nvidia, libGL_so_1_2_nvidia
  109. (
  110. # libglx
  111. mv /usr/lib/xorg/modules/extensions/libglx{.so,_so}
  112. ln -s libglx_so_nvidia /usr/lib/xorg/modules/extensions/libglx.so
  113. # libGL
  114. mv /usr/lib/libGL{.so.1.2.0,_so_1_2}
  115. ln -sf libGL_so_1_2_nvidia /usr/lib/libGL.so.1.2.0
  116. doGLsymlinks
  117. ) && echo "* nvidia gl/glx selected"
  118. ;;
  119. "ati")
  120. # is the ati port installed?
  121. checkInstalled ati
  122. # check for the existence of xorg backups
  123. local ebackups="$(getExistBackups)"
  124. [ ! -z "$ebackups" ] && infoRevert $ebackups
  125. # switch to ati stuff
  126. # conflicting files which ati provides:
  127. # libglx_so_ati, libGL_so_1_2_ati
  128. (
  129. # libglx
  130. mv /usr/lib/xorg/modules/extensions/libglx{.so,_so}
  131. ln -s libglx_so_ati /usr/lib/xorg/modules/extensions/libglx.so
  132. # libGL
  133. mv /usr/lib/libGL{.so.1.2.0,_so_1_2}
  134. ln -sf libGL_so_1_2_ati /usr/lib/libGL.so.1.2.0
  135. doGLsymlinks
  136. ) && echo "* ati gl/glx selected"
  137. ;;
  138. *)
  139. infoUsage
  140. ;;
  141. esac
  142. /sbin/ldconfig > /dev/null 2>&1
  143. }
  144. oldStuff() {
  145. for f in /usr/lib/xorg/modules/extensions/libglx_so \
  146. /usr/lib/libGL_so_1_2; do
  147. [ ! -e $f ] && infoMissing $f
  148. done
  149. # move the old xorg backups back into place
  150. (
  151. # libglx
  152. rm -f /usr/lib/xorg/modules/extensions/libglx.so
  153. mv /usr/lib/xorg/modules/extensions/libglx{_so,.so}
  154. # libGL
  155. mv /usr/lib/libGL{_so_1_2,.so.1.2.0}
  156. rm -f /usr/lib/libGL.so /usr/lib/libGL.so.1
  157. doGLsymlinks || echo "done"
  158. ) && echo "* xorg gl/glx selected"
  159. exit 0
  160. }
  161. # backup files which are also provided by nvidia and ati ports
  162. BACKUPS="
  163. /usr/lib/xorg/modules/extensions/libglx_so
  164. /usr/lib/libGL_so_1_2
  165. "
  166. # check for xorg ports; if they are not installed, why is this script even run?
  167. checkInstalled xorg-server xorg-mesa
  168. case $1 in
  169. status) doStatus ;;
  170. use) shift 1; doUse $@ ;;
  171. *) infoUsage ;;
  172. esac
  173. # End of file