docsmooth / vmware-bumblebee

Bash Script to start VMware Workstation under Bumblebee Primus/Optimus hybrid drivers
GNU General Public License v2.0
28 stars 10 forks source link

Adding other distro support #5

Closed Forge64 closed 9 years ago

Forge64 commented 9 years ago

Hello, I'm running Manjaro and Mint at the moment, your vmware-optimus works well under Mint, as it detects Ubuntu and the paths all work, but Arch/Manjaro are a whole other thing. I'm kludging together some detection and working out the right paths, and it looks like it won't be too hard to patch in support. Is this something I should push back upstream as a patch? I'm generally an admin, not a dev, but I'm happy to contribute what I can.

docsmooth commented 9 years ago

I tried to design it to make adding support for other distros pretty easy, but I don't have a lot of hardware to do real tests. either submit a patch here, or add a pull request (whichever you're more comfortable with), and we'll add it in together. hopefully it's just a matter of another /etc/release parsing, and some new paths. I can assist starting things off if you need, just post the contents of /etc/release, and I'll give you dummy code for the paths

Forge64 commented 9 years ago

Yeah, your work shows, I keep finding places where things could be easy or complicated, and you've gone with what's more modular, even when more difficult. Also, I had been running the script on Debian without trouble before, so it may not be worth breaking it out from Ubuntu at this point, likewise Mint is Ubuntu under the hood, still, so that's for another day. With Ubuntu-family, Fedora-family, and Arch-family, I think you'll have a very good percentage, but I'd be happy to setup Gentoo, SuSE, and anything else for testing.

Just figured out I wasn't on current, yet my copy was working with Workstation 10.0.4. No idea how that was, I probably chopped off all the safeties and checks. I've updated to current and am resuming tinkering.

Something has stopped me for the moment. "uname -p" returns "unknown" for me, and it's breaking 32/64 detection. I think I hardcoded this in my 1.6 working copy, rather than fix the underlying problem. Is this something you had seen before?

docsmooth commented 9 years ago

yes, I have seen uname -p show oddness, I'm adding a fix - try it.

Forge64 commented 9 years ago

Ok, will try it. Hardcoded x86_64 on my end to keep working, next ran into an issue where there are two hardcoded references to nvidia-304 in the fixlinks section. Intentional?

Forge64 commented 9 years ago

Ok, synced to head, looks good, added my paths and distro detects to yours, diff below. Special cased Manjaro because it doesn't mention Arch in the lsb-release anymore, and they claim they want to fork wider from Arch as time goes by. In the meantime, this detect works here.

Edit: Corrected Manjaro detect, had too few fi

<   fi
<     elif [  `which pacman` ]; then
<         OStype="arch"
<         if [ `grep -c -i "archlinux" /etc/lsb-release` -gt 0 ]; then
<             DISTRO="arch"
<             LIB32="/lib32"
<             ULIB32="/usr/lib32"
<             LIB64="/lib"
<             ULIB64="/usr/lib"
<         elif [ `grep -c -i "manjaro" /etc/lsb-release` -gt 0 ]; then
<             DISTRO="manjaro"
<             LIB32="/lib32"
<             ULIB32="/usr/lib32"
<             LIB64="/lib"
<             ULIB64="/usr/lib"
---
>         elif [ `grep -c -i "archlinux" /etc/lsb-release` -gt 0 ]; then
>             DISTRO="archlinux"
>             LIB32="donotknow"
>             ULIB32="donotknow"
>             LIB64="donotknow"
>             ULIB64="donotknow"
>             echo "ERROR: Do not know any paths for arch linux! Please edit the paths in line 93 appropriately!"
>             exit 2
117c110
<         # Fill in SUSE info here
---
>         # FIll in SUSE info her
Forge64 commented 9 years ago

And the newer uname check works nicely here, thanks.

Speaking of thanks, do you accept contributions? You've made my laptop+vmware work and I'd like to compensate you a beverage or two, if you don't mind.

Forge64 commented 9 years ago

Looks like my libs aren't quite laid out the same as Ubuntu. Ran through with bash -x (comment below) and it seems to trip up on locating the Nvidia libs, and it falls into the fallback link-making code where the hardcoded nvidia-304 reference is. My Nvidia libs seem to have a shorter path:

[forge@manjaro lib]$ locate libnvidia-tls.so /usr/lib/libnvidia-tls.so /usr/lib/libnvidia-tls.so.343.22 /usr/lib32/libnvidia-tls.so /usr/lib32/libnvidia-tls.so.343.22

Forge64 commented 9 years ago
[root@manjaro ~]# bash -x ./vmware.txt 
+ ACADAPTER=/sys/class/power_supply/AC
+ BATTERY=/sys/class/power_supply/BAT0
+ NVIDIAVERSION=nvidia-343
+ export NVIDIAVERSION
+ FORCE3D=a
+ DO3D=n
+ echo
+ egrep -q -w '(help|h|\?)'
+ '[' 1 -eq 0 ']'
++ which gksudo
+ '[' -x /usr/bin/gksudo ']'
++ which gksudo
+ SUDO='/usr/bin/gksudo -k'
+ determineos
++ uname -p
+ ARCH=unknown
+ '[' unknown = unknown ']'
++ uname -m
+ ARCH=x86_64
+ '[' x86_64 = unknown ']'
++ which dpkg
which: no dpkg in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
+ '[' ']'
++ which rpm
which: no rpm in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
+ '[' ']'
++ which pacman
+ '[' /usr/bin/pacman ']'
+ OStype=arch
++ grep -c -i archlinux /etc/lsb-release
+ '[' 0 -gt 0 ']'
++ grep -c -i manjaro /etc/lsb-release
+ '[' 2 -gt 0 ']'
+ DISTRO=manjaro
+ LIB32=/lib32
+ ULIB32=/usr/lib32
+ LIB64=/lib
+ ULIB64=/usr/lib
+ NVIDIA_DEST32=/usr/lib32/linux-gnu
+ NVIDIA_DEST64=/usr/lib/x86_64-linux-gnu
+ '[' x86_64 = x86_64 -o x86_64 = amd64 ']'
+ ULIB=/usr/lib
+ LIB=/lib
+ NVIDIA_DEST=/usr/lib/x86_64-linux-gnu
+ '[' -z /usr/lib ']'
+ '[' -z /lib ']'
+ '[' -z manjaro ']'
+ '[' -z /usr/lib/x86_64-linux-gnu ']'
+ export ARCH
+ export DISTRO
+ export OStype
+ export ULIB
+ export LIB
+ export NVIDIA_DEST
+ echo
+ egrep -q -w '(yes|y|f|force)'
+ '[' 1 -eq 0 ']'
+ echo
+ egrep -q -w '(n|no)'
+ '[' 1 -eq 0 ']'
+ echo
+ egrep -q -w '(r|remove)'
+ '[' 1 -eq 0 ']'
+ echo
+ egrep -q -w '(i|install)'
+ '[' 1 -eq 0 ']'
+ case "$-" in
+ echo ''\''-x'\'' is set, continuing in forked process'
'-x' is set, continuing in forked process
+ SHOPT='bash -x '
+ fixlinks
++ ls '/usr/lib/x86_64-linux-gnu/*nvidia*'
+ DEST=
+ '[' -z '' ']'
+ echo 'No Nvidia so links were found in /usr/lib/x86_64-linux-gnu, so they must be created.'
No Nvidia so links were found in /usr/lib/x86_64-linux-gnu, so they must be created.
+ echo 'You may be prompted for sudo credentials to do so now:'
You may be prompted for sudo credentials to do so now:
+ for file in '${ULIB}/nvidia-304/libnvidia-glcore*' '${ULIB}/nvidia-304/tls/libnvidia-tls.so*'
+ echo 'sudo ln -s /usr/lib/nvidia-304/libnvidia-glcore* /usr/lib/x86_64-linux-gnu'
sudo ln -s /usr/lib/nvidia-304/libnvidia-glcore* /usr/lib/x86_64-linux-gnu
+ sudo ln -s '/usr/lib/nvidia-304/libnvidia-glcore*' /usr/lib/x86_64-linux-gnu
ln: failed to create symbolic link ‘/usr/lib/x86_64-linux-gnu’: File exists
+ for file in '${ULIB}/nvidia-304/libnvidia-glcore*' '${ULIB}/nvidia-304/tls/libnvidia-tls.so*'
+ echo 'sudo ln -s /usr/lib/nvidia-304/tls/libnvidia-tls.so* /usr/lib/x86_64-linux-gnu'
sudo ln -s /usr/lib/nvidia-304/tls/libnvidia-tls.so* /usr/lib/x86_64-linux-gnu
+ sudo ln -s '/usr/lib/nvidia-304/tls/libnvidia-tls.so*' /usr/lib/x86_64-linux-gnu
ln: failed to create symbolic link ‘/usr/lib/x86_64-linux-gnu’: File exists
+ bbrun=/usr/bin/primusrun
+ '[' '!' -x /usr/bin/primusrun ']'
+ '[' '!' -x /usr/bin/primusrun ']'
+ '[' a = y ']'
+ '[' a = n ']'
++ cat /sys/class/power_supply/AC/online
+ ACSTATE=1
++ cat /sys/class/power_supply/BAT0/status
+ BATSTATE=Full
+ '[' -z Full -a -f /sys/class/power_supply/BAT0 ']'
+ BATSTATE=NF
+ '[' 1 = 0 -o XNF = XDischarging ']'
+ DO3D=y
+ export DO3D
+ '[' y = y ']'
+ export bbrun
+ '[' -z '' ']'
+ export XAUTHORITY=/root/.Xauthority
+ XAUTHORITY=/root/.Xauthority
+ XAUTHORITY=/root/.Xauthority
+ /usr/bin/gksudo -k /usr/bin/primusrun bash -x /usr/bin/vmware
/usr/bin/gksudo: invalid option -- 'x'
GKsu version 2.0.2

Usage: /usr/bin/gksudo [-u <user>] [options] <command>

  --debug, -d
    Print information on the screen that might be
    useful for diagnosing and/or solving problems.

  --user <user>, -u <user>
    Call <command> as the specified user.

  --disable-grab, -g
    Disable the "locking" of the keyboard, mouse,
    and focus done by the program when asking for
    password.
  --prompt, -P
    Ask the user if they want to have their keyboard
    and mouse grabbed before doing so.
  --preserve-env, -k
    Preserve the current environments, does not set $HOME
    nor $PATH, for example.
  --login, -l
    Make this a login shell. Beware this may cause
    problems with the Xauthority magic. Run xhost
    to allow the target user to open windows on your
    display!

  --description <description|file>, -D <description|file>
    Provide a descriptive name for the command to
    be used in the default message, making it nicer.
    You can also provide the absolute path for a
    .desktop file. The Name key for will be used in
    this case.
  --message <message>, -m <message>
    Replace the standard message shown to ask for
    password for the argument passed to the option.
    Only use this if --description does not suffice.

  --print-pass, -p
    Ask gksu to print the password to stdout, just
    like ssh-askpass. Useful to use in scripts with
    programs that accept receiving the password on
    stdin.

+ fixx11owners pulse
+ FILE=pulse
+ '[' -d /pulse -a y = y ']'
+ fixx11owners X11-display
+ FILE=X11-display
+ '[' -d /X11-display -a y = y ']'
+ exit 0
Forge64 commented 9 years ago

Yeah, it looks like Nvidiadest needs to be altered for Arch-based distros.

[root@manjaro ~]# locate libnvidia-glcore /usr/lib/libnvidia-glcore.so /usr/lib/libnvidia-glcore.so.343.22 /usr/lib32/libnvidia-glcore.so /usr/lib32/libnvidia-glcore.so.343.22 [root@manjaro ~]# locate libnvidia-tls /usr/lib/libnvidia-tls.so /usr/lib/libnvidia-tls.so.343.22 /usr/lib32/libnvidia-tls.so /usr/lib32/libnvidia-tls.so.343.22 [root@manjaro ~]#

Forge64 commented 9 years ago

Ok, I know this isn't useful to you as-is, but these modifications give me a working vmware-optimus on Manjaro. I'll test on Arch-main on Monday. Clearly the modifications break most other distros. I'm actually wondering if adding a symlink from /usr/lib/x86_64-linux-gnu/ to /usr/lib/ might not be quicker and cleaner. It would get things working without tearing this script apart, shouldn't harm the install, and would be easy to special case on first run, much like fixlibs is now. Maybe something like:

Detected an Arch-based distribution. For this script to work properly, we need to make a symlink from /usr/lib/x86_64-linux-gnu/ to /usr/lib/. If you decline, the script won't work, but no changes will be made. Make a link? (y/N)

19c19
< NVIDIAVERSION="nvidia"
---
> NVIDIAVERSION="nvidia-331-updates"
101,115c101,108
<   fi
<     elif [  `which pacman` ]; then
<         OStype="arch"
<         if [ `grep -c -i "archlinux" /etc/lsb-release` -gt 0 ]; then
<             DISTRO="arch"
<             LIB32="/lib32"
<             ULIB32="/usr/lib32"
<             LIB64="/lib"
<             ULIB64="/usr/lib"
<         elif [ `grep -c -i "manjaro" /etc/lsb-release` -gt 0 ]; then
<             DISTRO="manjaro"
<             LIB32="/lib32"
<             ULIB32="/usr/lib32"
<             LIB64="/lib"
<             ULIB64="/usr/lib"
---
>         elif [ `grep -c -i "archlinux" /etc/lsb-release` -gt 0 ]; then
>             DISTRO="archlinux"
>             LIB32="donotknow"
>             ULIB32="donotknow"
>             LIB64="donotknow"
>             ULIB64="donotknow"
>             echo "ERROR: Do not know any paths for arch linux! Please edit the paths in line 93 appropriately!"
>             exit 2
117c110
<         # Fill in SUSE info here
---
>         # FIll in SUSE info her
120c113
<     NVIDIA_DEST64="${ULIB64}"
---
>     NVIDIA_DEST64="${ULIB64}/x86_64-linux-gnu"
259c252
< PRELOAD="/usr/lib/primus/libGL.so.1"
---
> PRELOAD="/usr/lib/x86_64-linux-gnu/primus/libGL.so.1"
262c255
<     #PRELOAD="/usr/lib/optimus/libGL.so.1"
---
>     #PRELOAD="/usr/lib/x86_64-linux-gnu/optimus/libGL.so.1"
docsmooth commented 9 years ago

Thanks. With this info I can make this work. in my dayjob I have to support Solaris, HPUX, AIX, and all the Linuxes above, just not for this particular feature set, so multi-system compatibility is always loaded in my brain. I just don't see a lot of Arch-based systems normally.

Forge64 commented 9 years ago

Added the symlink to my system as a test. Script works perfectly afterwards, just have to change the nvidia version in the script and add my arch/manjaro detection, no other changes.

Had to disable khugepaged, as usual, but that's a whole other can of worms entirely.

Forge64 commented 9 years ago

Yes, detect/handle all *nix is a tall order. Workarounds like the symlink can make that mountain a little more manageable, even if it's not ideal. BTW, please don't overlook my offer of beverage compensation. You've saved me quite a bit of unhappiness with my M4800, so I'd be happy to return the favor a little.

docsmooth commented 9 years ago

OK, I'm adding in your patch for the paths. However, getting that added into the install script may require the splitting discussed in issue 6. I'm going to have to think about this a bit, so sync and try this version. Please REMOVE your symlink before testing though (re-add so tihngs work if required, while I work out the rest).

docsmooth commented 9 years ago

I figured out how to solve the NVIDIA path location without solving the issues in issue 5, checked in in commit: 2d9022e03b13bdec05ef7b32a0cd7a790381e15a so I'll close this. Please re-open when you get access to those laptops again if this fix doesn't solve it for you.

Forge64 commented 9 years ago

Symlink removed, pulled newest version, works perfectly. Thank you.

Forge64 commented 9 years ago

Just spotted a problem with my dist detection, I'm grepping for "archlinux" and it doesn't occur. Should be "arch linux". Grepping for just "arch" might cause false positives. Pasting the raw info below in case you'd like to do something better.

[forge@M4800-Arch ~]$ ls /etc/*-release /etc/arch-release /etc/lsb-release /etc/os-release@ [forge@M4800-Arch ~]$ cat /etc/os-release NAME="Arch Linux" ID=arch PRETTY_NAME="Arch Linux" ANSI_COLOR="0;36" HOME_URL="https://www.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://bugs.archlinux.org/" [forge@M4800-Arch ~]$ cat /etc/arch-release Arch Linux release [forge@M4800-Arch ~]$ cat /etc/lsb-release LSB_VERSION=1.4 DISTRIB_ID=Arch DISTRIB_RELEASE=rolling DISTRIB_DESCRIPTION="Arch Linux" [forge@M4800-Arch ~]$

docsmooth commented 9 years ago

added a space: https://github.com/docsmooth/vmware-bumblebee/commit/09012141f58f300dfde97a170d35a168723aa0eb