Permalink
Browse files

Merge Lekensteyn changes (+some other things)

  • Loading branch information...
1 parent efe06ec commit 98aaccd4aa09804080c25d4bcf51cd50b9ab5c65 @ArchangeGabriel ArchangeGabriel committed Aug 2, 2011
Showing with 119 additions and 117 deletions.
  1. +119 −117 install-files/optirun.ubuntu
View
236 install-files/optirun.ubuntu 100755 → 100644
@@ -29,148 +29,150 @@
### COMMENT
-#This is a optirun script which takes arguments: compression, architecture, display (just for testing purpose).
+#This is a optirun script which takes arguments: frame transfer, architecture, display (just for testing purpose).
#If the force argument is omitted, the script will not launch the app with bumblebee if the computer is on battery
#Usage :
-# ecoptirun -f -32 -c <compression_value> -d <display value>
+# optirun -f -32 -c <frame_transfer_value> -d <display value>
# -f : Force optirun : force the app to be run with bumblebee if on battery
-# -32 : 32Bits library : use the 32bits Nvidia driver (ecoptirun -32 is equivalent to optirun32)
-# -c <compression_value> : Compression : -c must be followed by jpeg, proxy, rgb, yuv or xv argument (See the VGL doc)
+# -32 : 32Bits library : use the 32bits Nvidia driver (optirun -32 is equivalent to optirun32)
+# -c <frame_transfer_value> : Frame transfer : -c must be followed by jpeg, proxy, rgb, yuv or xv argument (See the VGL doc)
# -d <display_value> : -d must be followed by :0, :1 or :2 argument (See the VGL doc)
### END COMMENT
#DEFAULT VALUE
source /etc/default/bumblebee
VGL_DRIVER="/usr/lib/nvidia-current"
-get_compression='0'
-get_display='0'
NVIDIABUSID=`grep BusID /etc/X11/xorg.conf.nvidia | sed -e "s/[ \t]*BusID[ \t]*\"\(.*\)\"/\1/g" |cut -d: -f2,3`
#READ ARGUMENTS
-#echo "$@"
-for arg in "$@"
- do
- case $arg in
- -f) ECO_MODE='0'
- echo "ECOPTIRUN : The application will be run with Bumblebee also if the computer is not plugged to a power supply"
- shift ;; #force optirun if on battery
- -32) VGL_DRIVER="/usr/lib32/nvidia-current"
- echo "ECOPTIRUN : The application will be run with Bumblebee and the 32bits Nvidia driver"
- shift ;; #launch vglrun with 32 bits nvidia driver
- -c) get_compression='1'
- shift ;;
- -d) get_display='1'
- shift ;;
- jpeg|proxy|rgb|yuv|xv)
- if [ "$get_compression" -eq "1" ]; then
- VGL_COMPRESS=$arg
- echo "ECOPTIRUN : Bumblebee is used with the compression : " $VGL_COMPRESS
- shift
- get_compression='0'
- else echo "The value jpeg, proxy, rgb, xv or xuv for the compression must be preceeded by the -c argument"
- exit 1
- fi
- ;;
- :0|:1|:2)
- if [ "$get_display" -eq "1" ]; then
- VGL_DISPLAY=$arg
- VGL_DISPLAY=:1
- echo "ECOPTIRUN : Bumblebee is used with the display : " $VGL_DISPLAY
- shift
- get_display='0'
- else echo "The value :0, :1: ,:2 for a display must be preceeded by the -d argument"
- exit 2
- fi
+#echo "$*"
+while :; do
+ case "$1" in
+ -f)
+ ECO_MODE='0'
+ echo "The application will be run with Bumblebee even if it's not connected to a power supply (e.g. running on battery)"
+ ;; #force optirun if on battery
+ -32)
+ VGL_DRIVER="/usr/lib32/nvidia-current"
+ echo "The 32-bit nVidia driver will be used"
+ ;; #launch vglrun with 32 bits nvidia driver
+ -c)
+ shift
+ case "$1" in
+ jpeg|proxy|rgb|yuv|xv)
+ VGL_COMPRESS=$arg
+ echo "Bumblebee will transfer frames using : $VGL_COMPRESS"
;;
- *)
- if [ "$get_compression" -eq "1" ]; then
- echo "The argument -c must be followed by one of this compression value : jpeg, proxy, rgb, xv or xuv."
- exit 1
- elif [ "$get_display" -eq "1" ]; then
- echo "The argument -d must be followed by one of this common display value : :0, :1, :2."
- exit 2
- else
- break
- fi
+ *)
+ echo "The frame transfer parameter -c must be followed by jpeg, proxy, rgb, yuv or xv."
+ exit 3
;;
- esac
- done
+ esac
+ ;;
+ -d)
+ shift
+ if ! [[ $1 =~ ^:[0-9]+$ ]]; then
+ VGL_DISPLAY=$1
+ echo "Bumblebee will use the $VGL_DISPLAY display for rendering"
+ else
+ echo "The display parameter -d must be followed by a colon and digits like :8"
+ exit 2
+ fi
+ ;;
+ --)
+ # commonly found in parameters, usage: optirun -- -not -recognised -as -param
+ break
+ ;;
+ -*)
+ echo "Unknown parameter: $1"
+ exit 3
+ ;;
+ *)
+ # begin of a command, assuming no optirun parameters after this one
+ break
+ ;;
+ shift
+done
-#echo "Arguments for the application:""$@"
+#echo "Arguments for the application: $*"
#echo "Eco mode:" $ECO_MODE
#echo "32 bits mode:" $lib32_mode
#echo "Compression mode:" $VGL_COMPRESS
#echo "Display:" $VGL_DISPLAY
-# if executed from a symlink named optirun32, use the 32b path
-
-if [ "${0##*/}" = "optirun32" -a -d /usr/lib32 ]; then
- VGL_DRIVER=/usr/lib32/nvidia-current
+# if executed from a symlink named optirun32, use the 32b path if exist
+if [ "${0##*/}" = "optirun32" -a -d /usr/lib32/nvidia-current ]; then
+ VGL_DRIVER=/usr/lib32/nvidia-current
fi
+msg_shown=false
show_msg()
{
- if ! $msg_shown; then
- echo "Another bumblebee powered application is running, keeping bumblebee alive."
- msg_shown=true
- fi
+ if ! $msg_shown; then
+ echo "Another bumblebee powered application is running, keeping bumblebee alive."
+ msg_shown=true
+ fi
}
#OPTIRUN
-function optirun_launcher
-{
-# Remove colon and everything before it: :1.0 -> 1.0
-display=${VGL_DISPLAY##*:}
-# Remove dot and everything after it: 1.0 -> 0
-display=${display%%.*}
-
-# test if Bumblebee's X server is running
-if [ ! -f /tmp/.X${display}-lock ]; then
- if [ `lspci -v -s $NVIDIABUSID |grep ! |wc -l` -eq 1 ]; then
- if ! sudo /etc/init.d/bumblebee enable; then
- echo "bumblebee could not be started - optirun cannot be executed."
- exit 1
- fi
- fi
-fi
-
-trap "echo 'Caught Ctrl+C'" INT
-
-######MODIFICATION######Comment : source /etc/default/bumblebee
-
-export VGL_READBACK
-export VGL_LOG
-######MODIFICATION######Replace : /usr/lib/nvidia-current with $VGL_DRIVER
-vglrun -c $VGL_COMPRESS -d $VGL_DISPLAY -ld $VGL_DRIVER "$@"
-
-msg_shown=false
-
-if [ "$STOP_SERVICE_ON_EXIT" != "NO" ]; then
- OPTIRUNS="/usr/bin/optirun /usr/bin/optirun32 /usr/bin/optirun64"
- while :; do
- # there is a space separating PIDs if multiple optirun instances are running
- if pidof -x $OPTIRUNS | grep -q ' '; then
- show_msg
- exit 0
- elif lsof -n -w "/usr/lib/nvidia-current/libnvidia-glcore.so"* >/dev/null; then
- show_msg
- sleep 1
- elif [ -f /usr/lib32/nvidia-current/libnvidia-glcore.so ]; then
- if lsof -n -w "/usr/lib32/nvidia-current/libnvidia-glcore.so"* >/dev/null; then
- show_msg
- sleep 1
- fi
- else
- break
- fi
- done
- if [ `lspci -v -s $NVIDIABUSID |grep ! |wc -l` -eq 0 ]; then
- sudo /etc/init.d/bumblebee disable
- fi
- if [ `lspci -v -s $NVIDIABUSID |grep ! |wc -l` -eq 0 ]; then
- sudo /usr/local/bin/bumblebee-disablecard
- fi
-fi
+optirun_launcher() {
+ # Remove colon and everything before it: :1.0 -> 1.0
+ display=${VGL_DISPLAY##*:}
+ # Remove dot and everything after it: 1.0 -> 1
+ display=${display%%.*}
+
+ # test if Bumblebee's X server is running
+ if [ ! -f /tmp/.X${display}-lock ]; then
+ # Bumblebee starts the X server on its own. If it was already running,
+ # it still returns 0 so no need for checking if the card is enabled or not
+ if ! sudo /etc/init.d/bumblebee enable; then
+ echo "bumblebee could not be started - optirun cannot be executed."
+ exit 1
+ fi
+ fi
+ # If for some reason the card is still disabled, enable it. This should
+ # never happen though!
+ if lspci -v -s $NVIDIABUSID | grep -q !; then
+ if [ -x /usr/local/bin/bumblebee-enablecard ]; then
+ echo "Something strange is going on. The card was still disabled even though X started without issues. Please report this"
+ sudo /usr/local/bin/bumblebee-enablecard
+ fi
+ fi
+
+ trap "echo 'Caught Ctrl+C'" INT
+
+ ######MODIFICATION######Comment : source /etc/default/bumblebee
+
+ export VGL_READBACK
+ export VGL_LOG
+ ######MODIFICATION######Replace : /usr/lib/nvidia-current with $VGL_DRIVER
+ vglrun -c $VGL_COMPRESS -d $VGL_DISPLAY -ld $VGL_DRIVER "$@"
+
+ if [ "$STOP_SERVICE_ON_EXIT" != "NO" ]; then
+ OPTIRUNS="/usr/bin/optirun /usr/bin/optirun32 /usr/bin/optirun64"
+ while :; do
+ # there is a space separating PIDs if multiple optirun instances are running
+ if pidof -x $OPTIRUNS | grep -q ' '; then
+ show_msg
+ exit 0
+ elif lsof -n -w /usr/lib*/nvidia-current/libnvidia-glcore.so* >/dev/null; then
+ show_msg
+ sleep 1
+ else
+ break
+ fi
+ done
+ if ! lspci -v -s $NVIDIABUSID | grep -q !; then
+ sudo /etc/init.d/bumblebee disable
+ fi
+ # BAD idea, do not disable the card if X is running! Trust me. Better
+ # keep it running than breaking the system.
+ #if ! lspci -v -s $NVIDIABUSID | -1 grep !; then
+ # if [ -x /usr/local/bin/bumblebee-disablecard ]; then
+ # sudo /usr/local/bin/bumblebee-disablecard
+ # fi
+ #fi
+ fi
}
@@ -185,8 +187,8 @@ done
if [ "$POWER_STATE" -eq "1" ] || [ "$ECO_MODE" -eq "0" ]; then
optirun_launcher $@
elif [ "$POWER_STATE" -eq "0" ]; then
- $@
+ "$@"
else
- $@
+ "$@"
fi

0 comments on commit 98aaccd

Please sign in to comment.