Created
December 28, 2017 18:24
-
-
Save goyox86/6c7b51cb7e4a17daa8d928fb9bb26dc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "fileutils" | |
require "optparse" | |
GDM_CONFIG_FILE = "/etc/gdm/custom.conf" | |
def nvidia_to_intel | |
# Removing bumblebee and friends | |
system "pacman --noconfirm -S bbswitch-dkms bumblebee primus" | |
# Forcing GDM to use X11 instead of wayland | |
FileUtils.mv(GDM_CONFIG_FILE, "#{GDM_CONFIG_FILE}.bkp") | |
gdm_config = File.open("#{GDM_CONFIG_FILE}.bkp").read | |
gdm_config.gsub!(/WaylandEnable=false/, "#WaylandEnable=false") | |
gdm_file_config = File.open(GDM_CONFIG_FILE, 'w') | |
gdm_file_config.write(gdm_config) | |
FileUtils.remove_file("#{GDM_CONFIG_FILE}.bkp") | |
# Disabling the NVIDIA HDMI fix systemd unit | |
system "systemctl disable nvidia-hdmi-audio-fix.service" | |
end | |
def intel_to_nvidia | |
# Removing bumblebee and friends | |
system "pacman --noconfirm -R bbswitch-dkms bumblebee primus" | |
# Installing the NVIDIA driver | |
system "pacman --noconfirm -S nvidia-dkms" | |
# Forcing GDM to use X11 instead of wayland | |
FileUtils.mv(GDM_CONFIG_FILE, "#{GDM_CONFIG_FILE}.bkp") | |
gdm_config = File.open("#{GDM_CONFIG_FILE}.bkp").read | |
gdm_config.gsub!(/#WaylandEnable=false/, "WaylandEnable=false") | |
gdm_file_config = File.open(GDM_CONFIG_FILE, 'w') | |
gdm_file_config.write(gdm_config) | |
FileUtils.remove_file("#{GDM_CONFIG_FILE}.bkp") | |
# Disabling the NVIDIA HDMI fix systemd unit | |
system "systemctl enable nvidia-hdmi-audio-fix.service" | |
end | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner =<<~BANNER | |
NAME | |
switch-gpu Switches between Intel + Bumblebee and pure NVIDIA propertary driver GPU setup | |
SYNOPSIS | |
switch-gpu -i Switches to Intel + Bumblebee | |
switch-gpu -n Switches to only NVIDIA | |
switch-gpu [--help] | |
DESCRIPTION | |
Switches between Intel + Bumblebee and pure NVIDIA propertary driver GPU setup | |
BANNER | |
token_msg = "Github acesss token." | |
opts.on("-i", "--intel", "Switches to Intel + Bumblebee") do |i| | |
options[:intel] = i | |
end | |
opts.on("-n", "--nvidia", "Switches to NVIDIA") do |n| | |
options[:nvidia] = n | |
end | |
end.parse! | |
nvidia_to_intel if options[:intel] | |
intel_to_nvidia if options[:nvidia] | |
puts "switch-gpu: restart your system to make changes take effect" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment