So this is just a fork of the original script, Adapted So that it works for Debian 9. I've only tested this on my machine. Which is a Lenovo YOGA. This Readme describes a step process of how to get this working. and some scripts
My nvidia card is NVIDIA Corporation GP107M [GeForce GTX 1050 Mobile]
echo "deb http://httpredir.debian.org/debian stretch-backports main contrib non-free" | sudo tee --append /etc/apt/sources.list > /dev/null
sudo apt-get update
apt-get install linux-headers-$(uname -r|sed 's/[^-]*-[^-]*-//')
Or if you are using a backports kernel as i am (needed for my touchpad)
apt-get install -t stretch-backports linux-headers-$(uname -r|sed 's/[^-]*-[^-]*-//')
apt-get install -t stretch-backports nvidia-driver
sudo apt-get install bumblebee-nvidia primus
sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install -t stretch-backports bumblebee-nvidia primus primus-libs:i386 libgl1-nvidia-glx:i386
sudo gpasswd -a $USER bumblebee
run the ./just-copy.sh
script. Or follow the steps in the script
If everything went well reboot. After the computer boots you should be able to use X with your normal Intel driver. but you need to check if bumblebee works as expected. On a console type
optirun glxgears -info
That should run glxgears using your nvidia card. With a poor performance, but in a way confirms you are on the right track
lsmod | grep nvidia
should show the nvidia kernel module is there as well
CTRL+SHIFT+F2 Will take you to another tty. We want to disable display manager (Asuming you are using sddm)
So stop your display manager systemctl stop sddm
if using kde you want the script to start kde when runned so
echo startkde > ~/.nvidia-xinitrc
That will start kde when running the nvidia script. Anyway lets test it :
Typing nvidia-xrun
Should run X with your drivers enabled.
If everything works run glxgears -info
You should see much much better performance than before.
exit X by logging out and run systemctl disable sddm
So that sddm does not start at boottime.
To run with the intel card run startx
To run with the nvidia card run nvidia-xrun
Hope this helps someone. If you run into any issues look at the original project. https://github.com/Witko/nvidia-xrun