#!/bin/bash

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

PID=$(ps ax | grep Xorg | grep :8 | grep -v grep | awk '{print $1}')

# Kill the second X server.
if [ ! -z $PID ]; then
   kill -15 $PID
fi

# Now you need to turn off nvidia card completely.
if lsmod | grep -q nvidia; then
  rmmod nvidia
fi
tee /proc/acpi/bbswitch <<<OFF
augtool --noload --file /etc/bumblebee/dual-monitor/disable.aug
service bumblebeed restart

